Guest User

Untitled

a guest
Sep 23rd, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #!/bin/bash
  2. ROOT_UID=0
  3. SUCCESS=0
  4. E_USEREXISTS=70
  5.  
  6. # Run as root, of course. (this might not be necessary, because we have to run the script somehow with root anyway)
  7. if [ "$UID" -ne "$ROOT_UID" ]
  8. then
  9. echo "Must be root to run this script."
  10. exit $E_NOTROOT
  11. fi
  12.  
  13. #test, if both argument are there
  14. if [ $# -eq 2 ]; then
  15. username=$1
  16. pass=$2
  17.  
  18. # Check if user already exists.
  19. grep -q "$username" /etc/passwd
  20. if [ $? -eq $SUCCESS ]
  21. then
  22. echo "User $username does already exist."
  23. echo "please chose another username."
  24. exit $E_USEREXISTS
  25. fi
  26.  
  27.  
  28. useradd -p `mkpasswd "$pass"` -d /home/"$username" -m -g users -s /bin/bash "$username"
  29.  
  30. echo "the account is setup"
  31.  
  32. else
  33. echo " this programm needs 2 arguments you have given $# "
  34. echo " you have to call the script $0 username and the pass "
  35. fi
  36.  
  37. exit 0
Add Comment
Please, Sign In to add comment