#!/bin/bash
MAILDIR="/etc/mail"
args=`echo $#`
logname=`echo $LOGNAME`
errmsg=""
errcode=0
if [ "$args" -ne 1 ]
then
	echo "1"
	errcode=1
	errmsg=`echo $errmsg Usage : $0 username`
fi
if [ "$logname" != "root" ]
then
	echo "2"
	errcode=1
	errmsg=`echo $errmsg Incorrect user. User should be root`
fi
# if user exists
ifexist=`grep "^$1:" /etc/passwd`
user="`echo $ifexist | cut -d: -f1 `"
if [ "`echo $1`" != "" -a "`echo $user`" = "`echo $1`" ]
then
	echo "3"
	errcode=3
	errmsg=`echo $errmsg User $1 already exists`
fi
if [ "$errcode" -eq 0 ]
then
	useradd -g users -s /bin/false $1
	passwd $1
	echo "$1	$1@Sendmail_BLR.utiisl.co.in">>$MAILDIR/genericstable
	makemap -r hash $MAILDIR/genericstable < $MAILDIR/genericstable
	echo "$1	$1@gsd.utiisl.co.in" >> $MAILDIR/dgenericstable
	makemap -r hash $MAILDIR/dgenericstable < $MAILDIR/dgenericstable
	echo "$1" >> $MAILDIR/trusted-users
	echo "Enter Password on gsd.utiisl.co.in. Send this password to postmaster:"
	stty -echo
	read rpassword
	stty echo
	echo "poll gsd.utiisl.co.in proto pop3 user '$1' to user '$1'  password '$rpassword' mda ' /usr/bin/procmail -d %T' " >> /root/.fetchmailrc
	echo "User account created with following parameters:"
	echo "User Name : $1"
	echo "Password : ********"
	echo "E-Mail : $1@gsd.utiisl.co.in"
	echo "POP3/SMTP Server : 10.10.100.200"
	echo "A Mail user with user name : $1 Password : $rpassword has been created on 10.10.100.200 server." | mail postmaster@utiisl.co.in
else
	echo "Unable to create user"
	echo "$errmsg"
fi

    Source: geocities.com/subhasisg/scripts/smarthost

               ( geocities.com/subhasisg/scripts)                   ( geocities.com/subhasisg)