You are not logged in.
Hi.
Well I'm writting this because the domain controller got fried yesterday. We got a very strong storm here and, while the trees were flying by the wind, the computer ceased to exist due to a lightning (I'll post pics later, there are a lot of people working here, retrieving evidence for insurance issues)
The real problem is that I need to set urgently around 200+ accounts for a temporary domain controller in order to get the network running as soon as possible. I got a list with all these people, but I don't know how to archieve this on bash. Would you guys help me?
The idea is pretty simple, I got my text file with names and I need the proper account get created. I know how to play with adduser, but I don't know how to program scripts.
The list.txt (for example)
Ariel Connor
Jack Smith
John Smith
the account's names, after using the script (first letter of the name + last name and add a number if the username exists on /etc/passwd, to avoid collisions). Again, I only need to process the names, because the groups and shells (among the other stuff) are all the same.
aconnor
jsmith
jsmith02
Any help would be greatly appretiatied.
Last edited by kjon (2009-08-14 16:30:33)
They say that if you play a Win cd backward you hear satanic messages. That's nothing! 'cause if you play it forwards, it installs windows.
Offline
Partially tested...
#!/bin/bash
LFILE='/tmp/list.txt'
IFS='
'
for NAME in $(cat $LFILE) ; do
FNAME=`echo $NAME | awk '{ print $1 }'`
LNAME=`echo $NAME | awk '{ print $2 }'`
UNAME="${FNAME:0:1}${LNAME}"
UNAME=`echo $UNAME | tr A-Z a-z`
C=1
NNAME=$UNAME
EXISTS=`grep -E '$UNAME' /etc/passwd`
while [ ! -z "$EXISTS" ] ; do
echo "found existing user $NNAME"
if [ ${#C} -eq 1 ] ; then
NNAME="${UNAME}0${C}"
else
NNAME="${UNAME}${C}"
fi
EXISTS=`grep -E '$NNAME' /etc/passwd`
C=$((C+1))
done
useradd $NNAME
done
exit 0
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
okay, thanks fukawi2. I'll try your approach (although I already created the users by hand -- my hands are still in pain). Thanks a lot again for your help.
Last edited by kjon (2009-08-16 14:48:49)
They say that if you play a Win cd backward you hear satanic messages. That's nothing! 'cause if you play it forwards, it installs windows.
Offline