Advertisement
Guest User

Untitled

a guest
May 5th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. #!/bin/bash
  2. if [ $(id -u) -eq 0 ]; then
  3. read -p "Enter username : " username
  4. read -s -p "Enter password : " password
  5. egrep "^$username" /etc/passwd >/dev/null
  6. if [ $? -eq 0 ]; then
  7. echo "$username exists!"
  8. exit 1
  9. else
  10. pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
  11. useradd -m -p $pass $username
  12. [ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!"
  13. fi
  14. else
  15. echo "Only root may add a user to the system"
  16. exit 2
  17. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement