Results 1 to 2 of 2
I'm still in the process of learning how to write shell scripts. I have a script for adding a user to the system ... Could anyone help me break down ...
- 08-20-2008 #1Just Joined!
- Join Date
- Aug 2008
- Posts
- 1
Shell Script
I'm still in the process of learning how to write shell scripts. I have a script for adding a user to the system ... Could anyone help me break down this script and explain what each lines does? I would greatly appreciate it!
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
- 08-20-2008 #2Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
Welcome to the forums.
Most people here would be willing to help with specific questions you might have. I suggest you write a description of what the lines appear to do, and people will attempt to guide you in the right direction.
Let us know what resource you are using -- a book, web page, etc.
Note also the use of CODE tags to make reading easier, like this:
... cheers, drlCode:a line of code in mono-space typeface
Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )


Reply With Quote