Hi, I am writing a bash script that will ask some questions to add a new user, then call the adduser bash script with the variables entered..
I then want to edit the /etc/mail/virtusertable and /etc/mail/genericstable files to set up my e-mail addresses...
The files must be entered like this:
mail@abc.com user1 <-- this is for the virtable.
user1 mail.abc.com <-- the genericstable.
Here is where I am so far, this script sucessfully creates the user, but now I need to write to these files and can't figure it out... I am still learning bash scripting and found most of this code, and modified it to meet my needs so far. Any help would be greatly appreciated.
#!/bin/sh
echo ================================
echo Please enter new users full name
echo ================================
read fullname
echo
echo ===============================
echo Please enter new users Username
echo ===============================
read name
grep -i $name /etc/passwd;echo $? > /dev/null |grep $name
if grep -i $name /etc/passwd
then
echo =========================================
echo The username you are attempting to enter
echo either already exists or is invalid.
echo Please verify username.
echo =========================================
exit 1
fi
echo
echo ====================================
echo The following userids are available
echo Please use the first available one:
echo ====================================
cut -d: -f3 /etc/passwd > /tmp/used
i=550
while [ $i -re 500 ]
do
grep "^$i$" /tmp/used > /dev/null 2>&1
if [ $? -ne 0 ]
then
#echo "UID $i is available for use"
fi
i=`expr $i - 1`
done
rm /tmp/used
echo ===============================
echo Please enter new users userid
echo ===============================
read uid
echo ===============================
echo Please enter new users Password
echo ===============================
read password
clear
echo =====================================
echo Group numbers are as follows:
echo =====================================
echo Group1 = 501
echo Group2 = 502
echo =====================================
echo Enter the group number for this user:
echo =====================================
read group
clear
echo =========================================
echo The following information will be used to
echo create the new user. Ensure that all the
echo information presented is correct. If
echo there are problems with the information
echo press CTRL + C to cancel this process and
echo start over again.
echo ==========================================
echo
echo "Users full name is : $fullname"
echo "Users username is : $name"
echo "Users UID is : $uid"
echo "Users Password is : $password"
echo "Users group id is : $group"
echo "Users work shell is : /bin/bash"
echo "Users home directory is : /home/$name"
echo "Users Comment is : $fullname"
echo
echo ========================================
echo Press enter to continue creating account
read _enter
echo
echo
echo ========================================
echo The account is now being created .......
echo ========================================
adduser -u $uid -g $group -c "$fullname" $name -p $password