Meghnaad
February 2nd, 2010, 07:48 AM
Hello I was asked to add multiple users to system with some random password I can not use perl ( I don't know perl )
I can only use bash So I came up with following script
#!/bin/bash
for i in `seq 1 80`
do
pass=$( apg -n 1 -m 6 -x 8 -M ncl )
user=$( sed -n "${i}p" names )
sudo useradd -m $user -g exam -d /home/$user -s /bin/bash -p `echo "$pass" | mkpasswd -s`
echo "$user,$pass" > out.dat
echo "Added $user,$pass" >&2
done
The Script Accepts user names stored in "names" file
ganerates a random password with "apg" and Stores usernames and passwords in "out.dat" ( I know before adding a user i should check if user with same name exists or not, but i'm planning to do it later )
Well My Problem is all goes well but when i tried adding 80 users the script took well more than 10 mins.
I've a decent Machine and also from man page of "apg" I've found that "apg" is the reason why my script executes slowly (well at least I believe that )
can you help me speeding up the script ?
I can only use bash So I came up with following script
#!/bin/bash
for i in `seq 1 80`
do
pass=$( apg -n 1 -m 6 -x 8 -M ncl )
user=$( sed -n "${i}p" names )
sudo useradd -m $user -g exam -d /home/$user -s /bin/bash -p `echo "$pass" | mkpasswd -s`
echo "$user,$pass" > out.dat
echo "Added $user,$pass" >&2
done
The Script Accepts user names stored in "names" file
ganerates a random password with "apg" and Stores usernames and passwords in "out.dat" ( I know before adding a user i should check if user with same name exists or not, but i'm planning to do it later )
Well My Problem is all goes well but when i tried adding 80 users the script took well more than 10 mins.
I've a decent Machine and also from man page of "apg" I've found that "apg" is the reason why my script executes slowly (well at least I believe that )
can you help me speeding up the script ?