Guest User

Untitled

a guest
Apr 13th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. usage() {
  4. cat <<-EOT
  5. usage: $0 options
  6.  
  7. Options:
  8.  
  9. -u Username
  10. -p Password
  11. -d Create database
  12.  
  13. EOT
  14. }
  15.  
  16. DB=0
  17.  
  18. while getopts 'u:p:d' OPTION
  19. do
  20. case $OPTION in
  21. u) USER=$OPTARG
  22. ;;
  23.  
  24. p) PASS=$OPTARG
  25. ;;
  26.  
  27. d) DB=1
  28. ;;
  29. esac
  30. done
  31.  
  32. if [ "$USER" = "" ] || [ "$PASS" = "" ]; then
  33. usage
  34. exit 1
  35. fi
  36.  
  37. groupadd $USER
  38. useradd -m -g $USER -s /bin/bash -p $PASS $USER
  39.  
  40. if [ $DB == 1 ]; then
  41. mysqladmin create $USER
  42. mysql -e "grant all privileges on $USER.* to $USER@localhost identified by '$PASS'"
  43. fi
  44.  
  45. exit 0
Add Comment
Please, Sign In to add comment