Advertisement
mastechr

Untitled

Dec 12th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. #!/bin/bash
  2. # Admin Script for adding / modifying / deleting users
  3. # Script created by Robert Pearce
  4. # Oct 2013
  5.  
  6. # id -u is used to identify the userid (number) of who
  7. # is currently running this script.
  8. # The value is then compared to 0 (zero), as root UID is 0 zero.
  9. # We know that we need to be root for these types of operation. It's
  10. # kind of pointless to do anything else unless we identify who
  11. # is running the script
  12.  
  13. id=`id -u`
  14. if [[ $id -ne 0 ]]; then
  15. # echoing the fact that some ran this as someone other than root
  16. echo "This script needs to be run as root"
  17. else
  18. # just testing to see what happens otherwise
  19. echo "You are root, or equivaent, so we can continue"
  20. fi
  21.  
  22. # Clear the screen to clean it up
  23. clear
  24.  
  25. # Declaring a variable called menu - setting it to yes. While this is true
  26. # the loop will continue to clear the screen, and draw the menu.
  27.  
  28. menu=yes
  29. while [ $menu = yes ];
  30. do
  31. clear
  32.  
  33.  
  34. # Using echo to display the menu. \t\t are tabs, and \n is a new line
  35. echo -e "\t\t User Account Admin Menu\n"
  36. echo -e "1.\t Add a New User\n"
  37. echo -e "2.\t Edit a User\n"
  38. echo -e "3.\t Delete an Existing User\n"
  39. echo -e "4.\t Exit the Program\n"
  40. echo -n "Enter Selection: "
  41. # read is a builtin command capturing the users selection
  42. # we called the variable "selection"
  43. read selection
  44.  
  45. echo $selection
  46.  
  47. # In this scenario, we can use a case - or menu style logic structure
  48. case $selection in
  49. 1) #Adding a User
  50. echo -e "Enter a user name:"
  51. read name
  52.  
  53. echo "Enter a comment:"
  54. read comment
  55.  
  56. echo "Enter a password:"
  57. read password
  58.  
  59. echo "Adding "$name" "$comment" "$password" "
  60. echo "sudo useradd -m -c "$comment" -p "mkpasswd -m sha-512" "$password" "
  61. sleep 2
  62. ;;
  63. 2) #Edit a User
  64. echo -n "Add code for user editing"
  65. sleep 2
  66. ;;
  67. 3) #Deleting a User
  68. echo "Add code for user deletion"
  69. sleep 2
  70. ;;
  71. 4) #Exit Program
  72. echo "Add code to exit"
  73. sleep 1
  74. menu=no
  75. ;;
  76. *) #Capture all other input (error handling)
  77. echo "Unrecognized selection"
  78. sleep 1
  79. exit 1
  80. esac
  81. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement