Printable Version of Topic

Click here to view this topic in its original format

Linuxhelp _ Programming in Linux _ Writing shell script

Posted by: shellscriptwriter May 4 2015, 04:48 AM

I am trying to write a script that creates users and adds them to groups.
The script to automate the creation of users is:
#!/bin/bash
# Script to add a user to Linux system
if [ $(id -u) -eq 0 ]; then
read -p "Enter username : " username
read -s -p "Enter password : " password
egrep "^$username" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
echo "$username exists!"
exit 1
else
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
useradd -m -p $pass $username
[ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!"
fi
else
echo "Only root may add a user to the system"
exit 2
fi


How could I modify this so that this shell script also additionally adds people to 2 specific groups?

Posted by: michaelk May 4 2015, 06:28 AM

You can add a menu.

bash.cyberciti.biz/decision-making/menu-driven-shell-script/

Posted by: shellscriptwriter May 8 2015, 12:08 PM

QUOTE (michaelk @ May 4 2015, 06:28 AM) *
You can add a menu.

bash.cyberciti.biz/decision-making/menu-driven-shell-script/

thanks

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)