Advertisement
Guest User

Untitled

a guest
Jul 19th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ROOT_UID=0
  4. SUCCESS=0
  5. E_USEREXISTS=70
  6.  
  7. # Check if root
  8. if [ "$UID" -ne "$ROOT_UID" ]
  9. then
  10. echo "Must be root to run this script."
  11. exit $E_NOTROOT
  12. fi
  13.  
  14. #test if both arguments are there
  15. if [ $# -eq 2 ]; then
  16. username=$1
  17. pass=$2
  18.  
  19. # Check if user already exists.
  20. grep -q "$username" /etc/passwd
  21. if [ $? -eq $SUCCESS ]
  22. then
  23. echo "User $username does already exist."
  24. echo "please choose another username."
  25. exit $E_USEREXISTS
  26. fi
  27.  
  28.  
  29. useradd $username --no-create-home -g wok-user
  30. echo "$username:$pass" | chpasswd
  31. echo "The account is successfully created!"
  32.  
  33. else
  34. echo " User creation needs 2 arguments, you have given $#. "
  35. echo " Call the script $0 username and the pass "
  36. fi
  37.  
  38. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement