If you are asking for a script that will use a file as input, that's fairly easy, provided that the file is delineated with a specific character, or each part of the file is an exact number of spaces, ie:
file 1:
Code:
brown, john, bo2x6&@!
Smith, Marge, alks84r32
file 2:
Code:
brown john bosx6&@!
Smith marge alks84r32
The script would look something like:
Code:
#!/bin/bash
FL=/path/to/users.file
TTL=`cat $FL|wc -l`
cnt=1
until [ "$TTL" = "$cnt" ] ; do
LN=`cat $FL|head -n$cnt|tail -n1`
# file 1 example:
LSTNM=`echo $LN|cut -f1 -d',' | tr 'A-Z' 'a-z'` ; # strip any upper-case letters to lower-case
FRSTNM=`echo $LN|cut -f2 -d',' | tr 'A-Z' 'a-z'`
PASSWD=`echo $LN|cut -f2 -d','`
# file 2 example:
LSTNM=`echo $LN|cut -c1-12 | tr 'A-Z' 'a-z'`
FRSTNM=`echo $LN|cut -c13-24 | tr 'A-Z' 'a-z'`
PASSWD=`echo $LN|cut -c25-999` ;# to get everything to the end of the line
# create login name
LGN=`echo $FRSTNM|cut -c1-2
LGN=$LGN$LSTNM
# create account
echo $PASSWD
adduser $LGN
done
# End of script
adduser must be run as root. You can either
sudo su - first (depending on your distribution, you might just do
su -) or put
sudo adduser $LGN on the appropriate line. The first cycle through the file, you will be prompted for the correct sudo password. After that, you won't be prompted again.
Because of security requirements, you can't automate the password creation, so this script will prompt you for the password, which you can just copy and paste, twice, from the echo command above the prompt.
This is a quick and dirty example. YMMV (your mileage may vary).