mirror of
https://github.com/techarkit/shell-scripting-tutorial.git
synced 2025-07-28 23:28:40 +00:00
New Script files
This commit is contained in:
18
useradd.sh
Normal file
18
useradd.sh
Normal file
@ -0,0 +1,18 @@
|
||||
#!/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
|
Reference in New Issue
Block a user