[SOLVED] Re: useradd fails - script to generate users
waldbauernbub at gmx.at
Mon Jun 15 12:03:58 UTC 2009
Markus Schönhaber schrieb:
> Franz Waldmüller:
> Tip: to see how the command to be executed really looks like, precede it
> with echo, e. g.
> echo useradd --password $PASS -m -d $HOME_BASE/$USER $USER -e 2009-12-31
> or, probably even better, use bash's
> set -x
I used echo on to display the variable but I didn't consider using it on
the useradd command. Thumbs up for this idea!
-> I just discovered 2 blank lines at the end of the input textfile.
After deleting them everything seams to be ok.
A detailed problem description would have been helpful (shame on me): I
already used echo and everything seemed to work fine, but after adding
my 3 testusers I was prompted two times for a password.
Here is the link to the source script which I modified to my needs with
your help (this sample didn't encrypt the passwords):
Thank you Markus for your help.
Below is the script which might interest others as well:
Task: add users to a Linux system out of a text file and assign passwords:
I created the textfile with gnumeric, the passwords where created with
pwgen -N 20 8 (copy and paste to gnumeric)
here is a sample of the text file (userename password groupname):
erase1 fee45eghebairiodeeni erasgrp
erase2 phuashuezuire%wiutha erasgrp
erase3 jaehuniew&ahbieghatu erasgrp
Attention don't leave any blank lines at the end of the document
Here is the script which adds the users to the system
# Path to the homedirectories of the created users
cat $NEW_USERS | \
while read USER PASSWORD GROUP
# the -e command will disable the created users at the given date
useradd -p $PASS -g $GROUP -e 2009-12-31 -m -d $HOME_BASE/$USER $USER
More information about the ubuntu-users