Hi frnds
i am newbie in linux and trying to write a simple script for adding users.the problem is i am running a while loop under function and loop is running for 3 time more than limit.Here is my Script and output pls help me out :
# CREATE N NO. OF USERS WITH PASSWORD IN SYSTEM
# ./users to run the script
# CREATE A FUNCTION CALLED ADD()
ADD ()
{
while [ $i -le $no ]
do
echo -e " Please enter the user name :\t\c"
read USER
# Search in /etc/passwd file for user existence
output=`cat /etc/passwd | grep $USER | cut -d: -f1`
if [ "$output" = "$USER" ]
then
echo " Opps ! $USER is already exist Please Enter again"
## Call ADD Function in case of User already exist
ADD
fi
useradd $USER
echo -e " Please enter the Password of the user :\t\c"
read PASSWD
echo $PASSWD | passwd --stdin $USER
echo "$USER creates successfully"
i=`expr $i + 1`
done
}
clear
echo -e " Please Enter How many users want to create :\t\c"
read no
i=1
# Call ADD Function
ADD
OUTPUT of Script :
Please Enter How many users want to create : 2
Please enter the user name : viv
Opps ! viv is already exist Please Enter again
Please enter the user name : vishnu
Opps ! vishnu is already exist Please Enter again
Please enter the user name : ram
useradd: user 'ram' already exists
Please enter the Password of the user : kev
Changing password for user ram.
passwd: all authentication tokens updated successfully.
ram creates successfully
Please enter the user name : john
Please enter the Password of the user : john
Changing password for user john.
passwd: all authentication tokens updated successfully.
john creates successfully
useradd: user 'john' already exists
Please enter the Password of the user : john
Changing password for user john.
passwd: all authentication tokens updated successfully.
john creates successfully
useradd: user 'john' already exists
Please enter the Password of the user : jhon
Changing password for user john.
passwd: all authentication tokens updated successfully.
john creates successfully
[root@Riyansh Scripts]#
pls help me out
thanks
vaibhav