Results 1 to 1 of 1
Basically I have to add a user to the system, full name is upper case in the comment field of the password file, placing them in appropriate groups with a ...
- 02-18-2011 #1Just Joined!
- Join Date
- Jan 2011
- Posts
- 87
[SOLVED] Having trouble finishing up a bash script
Basically I have to add a user to the system, full name is upper case in the comment field of the password file, placing them in appropriate groups with a default password of 123456. Username has to be first 5 letters of last name and first letter of first name all lower case. Then I have to be prompted to add another user. I'm not sure if I have the "if then else fi" "while do done" and the "for do done" statements even set up right. This is my first time having to do something like this, and I just want to make sure I have it right.
Code:DECISION=yes while [ "$DECISION" = "yes" ] do echo "Please enter your last name" read LNAME echo "Please enter your first name" read FNAME echo "Please enter your initial group" read IGROUP echo "Please enter any additional groups" read AGROUP IGROUPL=`echo $IGROUP | tr [:upper:] [:lower:]` AGROUPL=`echo $AGROUP | tr [:upper:] [:lower:]` LNAMEU=`echo $LNAME | tr [:lower:] [:upper:]` FNAMEU=`echo $FNAME | tr [:lower:] [:upper:]` USRNM1=`echo $LNAME | cut -c -5 | tr [:upper:] [:lower:]` USRNM2=`echo $FNAME | cut -c 1 | tr [:upper:] [:lower:]` USRNM=$USRNM1$USRNM2 useradd -c "$FNAMEU $LNAMEU" -g $IGROUPL -G $AGROUPL $USRNM echo 123456 | passwd $USRNM --stdin echo "Would you like to add another user?(yes/no)" read YESNO DECISION=`echo $YESNO | tr [:upper:] [:lower:]` DONE LOOP=1 while [ "$DONELOOP" -eq "1" ] do if [ $DECISION == "yes" ]; then DECISION=yes DONE LOOP=2 else if [ "$DECISION" == "no" ]; then echo "Thank you for using this program" DONE LOOP=2 else echo "Please use a correct option. (yes/no)" read YESNO DECISION=`echo $YESNO | tr [:upper:] [:lower:]` fi done done


