Advertisement
Guest User

Untitled

a guest
Apr 13th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #!/bin/bash
  2. if [ $(id -u) -eq 0 ]; then
  3. read -p "Insert username" username
  4. read -s -p "Insert password" password
  5. grep '$username' /etc/passwd >/dev/null
  6. if [ $? -eq 0 ]; then
  7. echo "User exists"
  8. exit 1
  9. else
  10. useradd -m -p $password $username
  11. [ $? -eq 0 ] $$ echo "Success" || echo "Failed"
  12. fi
  13. else
  14. echo "Youre not root, could not do this"
  15. exit 2
  16. fi
  17.  
  18. [root@ip-10-0-7-125 script_collection]# ./them_user.sh
  19. Insert usernameoidech
  20. Insert password./them_user.sh: line 11: [: missing `]'
  21. Failed
  22.  
  23. #!/bin/bash
  24. if [ $(id -u) -eq 0 ]; then
  25. read -p "enter username: " username
  26. read -s -p "enter pass: " password
  27. egrep "^$username" /etc/passwd >/dev/null
  28. if [ $? -eq 0 ]; then
  29. echo "$username exists"
  30. exit 1
  31. else
  32. pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
  33. useradd -m -p $pass $username
  34. [ $? -eq 0 ] && echo "User has been added to system" || echo "Failed"
  35. fi
  36. else
  37. echo "only root could add"
  38. exit 2
  39. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement