• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

More refined script

sourceninja

Diamond Member
I have a ubuntu server that needs a few hundred accounts created on it. All of these accounts are in this format

student[room number]u[user number] (example student123u1 or student225u30)
50 accounts will be made per room and the passwords will be identical for the user name. These accounts are going to be used for a semester then removed at the end of the semester and replaced.
I have written the following script

roomlist.txt is a text file with the following format
student123u
student563u
student121u
etc
#!/bin/bash
for y in `more roomlist.txt`
do
for x in {1..50}
do
user=$y$x
password=`mkpasswd $user`
useradd $user -m -p $password
echo Account created for User: $user
done
done

Similarly I have a script that replaces the inner do loop with userdel -r $user to delete each user as so:

#!/bin/bash
for y in `more roomlist.txt`
do
for x in {1..50}
do
user=$y$x
userdel -r $user
echo Account deleted for User: $user
done
done

Any suggestions on a better way to write these scripts or stream line them?
 
Do the scripts work? If so I'd say you did good enough. I'm not sure how you're splitting up the username from the rest of the string though. I'd probably use cat instead of more. Actually I probably would've started with perl and a regexp to split up the lines since I'm more comfortable with them.
 
Back
Top