Below is my code to create a user account but it doesn't take a password automatically. I have to run the password command seperately to do this
What I want to do is to be able to accept the password in a script.
In linux with the "useradd' command you can give the "-p" flag to accept the password
#!/opt/csw/bin/bash
clear
# Script to add a user to this Linux system
if [ $(/usr/xpg4/bin/id -u) -eq 0 ]; then # check if user is root
read -p "Enter Group Name : " groupname # Enter group name
while [ -z $groupname ]|| egrep "^$groupname" /etc/group 1>/dev/null;
do
echo -ne "Either group exists or you entered a blank, enter groupname again: ";read -e groupname
done
echo -ne "\nPlease Enter your Group ID Number: ";read -ern3 gid
while [[ ! $gid =~ ^[0-9]+$ ]]||egrep $gid /etc/group >/dev/null;
do
echo -ne "Please re-enter your group id positive intergers only: ";read -ern3 gid
done
echo -ne "\nPlease Enter your User ID Number: ";read -ern5 uid
while [[ ! $uid =~ ^[0-9]+$ ]]||egrep $uid /etc/passwd >/dev/null;
do
echo -ne "\nPlease re-enter your uid positive intergers only: ";read -ern5 uid
done
echo -ne "\nEnter a Comment : "; read -e comment
commentstatic="Staging Account"
echo -ne "\nEnter your Staging FTP directory location.......... "; read -e ftpdir
while [ ! -d "$ftpdir" ];
do
echo -ne "\n$ftpdir Directory Not Found! Please re-enter: "; read ftpdir
done
username="s"$groupname #getting username from groupname
/opt/csw/bin/gsed -e '/ftp/s/$/,'"$username"'/' -i /etc/group # this line is to add user to ftp group.........."
echo -e "\nAdding group $groupname......." #Adding group to group file
groupadd -g $gid $groupname
echo -e "Finished adding $groupname to group file......."
echo -e "\nAdding user to system.........."
/usr/sbin/useradd -u $uid -g $groupname -c "$comment $commentstatic" -d /forms1/prodenv/$groupname $username
sleep 2
echo -e "\nFinished adding $username to password file......." #Adding user to password file
echo -e "\nLinking source directory to home directory......."
cd /forms1/prodenv
ln -s /stage001/stageenv/$username $groupname
echo -e "\nDone linking home directory......"
echo -e "\nLinking source storage directory to home storage directory......."
cd /forms/
ln -s /stage001/stageenvsa/${username}sa ${groupname}sa
echo -e "\nDone linking storage directory......"
echo -e "\nSetting security on directories................"
chown $username:$groupname /stage001/stageenv/$username
chown $username:$groupname /stage001/stageenvsa/${username}sa
chmod 775 /stage001/stageenv/$username
chmod 775 /stage001/stageenvsa/${username}sa
echo -e "\nFinished setting security on directories................"
echo -e "\nSetting up the FTP directory................"
cd /ftp
ln -s $ftpdir $username
echo -e "\nSetting security on FTP directory................"
chown $username:ftp $ftpdir
chmod 775 $ftpdir
echo -e "\nFinished setting security on FTP directory................"
echo -e "\nSetting up services file................"
serviceadd=`tail -1 /etc/services | awk '{print $2}'| cut -c 1-5`
let serviceadd++
echo -e "$username""trck" "\t$serviceadd/tcp" "\t\t# $comment Staging Svc Account" >> /etc/services
echo -e "Finished setting up services file................"
echo ""
echo ""
fi