Script to add user and alias

I have seen similar script like this, I just added some arguments to make it suffice.


# Script to add a user with password and alias
# Jeffrey Dante


if [ $(id -u) -eq 0 ]; then
read -p “Enter username : ” username
read -p “Enter email address: ” email
read -s -p “Enter password : ” password
egrep “^$username” /etc/passwd >/dev/null
egrep “^$email” /etc/aliases >/dev/null
if [ $? -eq 0 ]; then
echo “$username already exists!”
echo “$email already exist!”
echo “Make it sure that you do not have desame username and emaill address!”
exit 1
pass=$(perl -e ‘print crypt($ARGV[0], “password”)’ $password)
$ADDUSER -s /sbin/nologin -m -p $pass $username -G 100 $1
echo -e “$email:\t$username” >> /etc/aliases
echo -e “$email” >> /usr/files/addresses.txt
[ $? -eq 0 ] && echo “User has been added to system!” || echo “Failed to add a user!”

echo “Only root may add a user to the system”
exit 2


Mag-iwan ng Tugon

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Baguhin )

Twitter picture

You are commenting using your Twitter account. Log Out / Baguhin )

Facebook photo

You are commenting using your Facebook account. Log Out / Baguhin )

Google+ photo

You are commenting using your Google+ account. Log Out / Baguhin )

Connecting to %s