Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #!/bin/bash
  2. #################################################################
  3. ################## Create User mongod ################
  4. #################################################################
  5.  
  6. #Creates mongod group and user with password
  7. #call the script with password for mongod as arguements
  8. ROOT_UID=0
  9. SUCCESS=0
  10. E_USEREXISTS=70
  11.  
  12. # Run as root
  13. if [ "$UID" -ne "$ROOT_UID" ]
  14. then
  15. echo "Must be root to run this script."
  16. exit $E_NOTROOT
  17. fi
  18.  
  19. #test, if argument is there
  20. if [ $# -eq 1 ]; then
  21. group=mongod
  22. username=mongod
  23. pass=$1
  24.  
  25. # Check if user already exists.
  26. grep -q "$username" /etc/passwd
  27. if [ $? -eq $SUCCESS ]
  28. then
  29. echo "User $username does already exist."
  30. echo "please chose another username."
  31. exit $E_USEREXISTS
  32. fi
  33. groupadd $group
  34. useradd -p $pass -d /home/$username -m -g $group -s /bin/bash $username
  35.  
  36. echo "the account is setup"
  37.  
  38. else
  39. echo " this programm needs 2 arguments you have given $# "
  40. echo " you have to call the script $0 password"
  41. fi
  42. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement