Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )

Advanced DNS Management
New ZoneEdit. New Managment.


Sign Up Now
Reply to this topicStart new topic
> Shell Script
post Aug 20 2008, 11:24 AM
Post #1

Whats this Lie-nix Thing?

Group: Members
Posts: 1
Joined: 20-August 08
Member No.: 13,623

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
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!"
echo "Only root may add a user to the system"
exit 2
Go to the top of the page
+Quote Post
post Aug 31 2008, 02:25 AM
Post #2

Its GNU/

Group: Support Specialist
Posts: 1,807
Joined: 23-January 03
Member No.: 360

A good place to start is to read advanced bash programming. It will explain the fundamentals of bash programming.
search for conditional statements i.e. if then else,
input statements i.e. read
environment variables i.e. #?

In a nutshell.
adduser is a utility to add a user. It can only be run as root and root's id is always 0 (zero).
egrep is a pattern matching console utility. In this case it is used to find if a user already exists.
perl is a shell language and crypt is a perl built in DES encryption function. In this case it is encrypting the password.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:


RSS Lo-Fi Version Time is now: 21st July 2018 - 08:56 AM