Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Admin Script for adding / modifying / deleting users
- # Script created by Robert Pearce
- # Oct 2013
- # id -u is used to identify the userid (number) of who
- # is currently running this script.
- # The value is then compared to 0 (zero), as root UID is 0 zero.
- # We know that we need to be root for these types of operation. It's
- # kind of pointless to do anything else unless we identify who
- # is running the script
- id=`id -u`
- if [[ $id -ne 0 ]]; then
- # echoing the fact that some ran this as someone other than root
- echo "This script needs to be run as root"
- else
- # just testing to see what happens otherwise
- echo "You are root, or equivaent, so we can continue"
- fi
- # Clear the screen to clean it up
- clear
- # Declaring a variable called menu - setting it to yes. While this is true
- # the loop will continue to clear the screen, and draw the menu.
- menu=yes
- while [ $menu = yes ];
- do
- clear
- # Using echo to display the menu. \t\t are tabs, and \n is a new line
- echo -e "\t\t User Account Admin Menu\n"
- echo -e "1.\t Add a New User\n"
- echo -e "2.\t Edit a User\n"
- echo -e "3.\t Delete an Existing User\n"
- echo -e "4.\t Exit the Program\n"
- echo -n "Enter Selection: "
- # read is a builtin command capturing the users selection
- # we called the variable "selection"
- read selection
- echo $selection
- # In this scenario, we can use a case - or menu style logic structure
- case $selection in
- 1) #Adding a User
- echo -e "Enter a user name:"
- read name
- echo "Enter a comment:"
- read comment
- echo "Enter a password:"
- read password
- echo "Adding "$name" "$comment" "$password" "
- echo "sudo useradd -m -c "$comment" -p "mkpasswd -m sha-512" "$password" "
- sleep 2
- ;;
- 2) #Edit a User
- echo -n "Add code for user editing"
- sleep 2
- ;;
- 3) #Deleting a User
- echo "Add code for user deletion"
- sleep 2
- ;;
- 4) #Exit Program
- echo "Add code to exit"
- sleep 1
- menu=no
- ;;
- *) #Capture all other input (error handling)
- echo "Unrecognized selection"
- sleep 1
- exit 1
- esac
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement