Results 1 to 2 of 2
Hi everyone im new in the forum. I got to speak about a script that add users. What i want is a Simple bash script that addusers with password.Also if ...
- 03-18-2010 #1Just Joined!
- Join Date
- Mar 2010
- Posts
- 1
Shell script for adding users! help needed
Hi everyone im new in the forum. I got to speak about a script that add users. What i want is a Simple bash script that addusers with password.Also if it is possible to read from a file the username to add and check if the username is in use.
The script: (not my)
Shell script to add a user
#!/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
Questions
1) how can i test if it works?
2) is it a bash script or shell script?
3) Most important question if someone could give me a brief explanation of how the script works step by step!
4) Differences between the scripting syntax with programming languages
I am not expecting for someone to sit and explain everything to me unless he is able and willing to do it, but i would appriciate some help
Regards George
P.S: i am new in scripting so if someone will reply please try to give easy explanations :P thanks
)
- 03-18-2010 #2
I think your best bet is one of the many...many Bash tutorials out there
Bash Guide for BeginnersMake mine Arch Linux


Reply With Quote