Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # MD Harrington 25-9-2020
- # A menu driven shell script template for Maria DB
- ## ----------------------------------
- # Step #1: Define variables
- # ----------------------------------
- EDITOR=Geany
- RED='\033[0;41;30m'
- STD='\033[0;0;39m'
- # ----------------------------------
- # Step #2: User defined function
- # ----------------------------------
- pause(){
- read -p "Press [Enter] key to continue..." fcnEnterKey
- }
- one(){
- echo "Stopping Maria DB Service"
- sudo systemctl stop mariadb.service
- pause
- }
- # do something in two()
- two(){
- echo "Restarting Maria DB Service "
- sudo systemctl restart mariadb.service
- pause
- }
- # do something in three()
- three(){
- echo "Checking Maria DB Service Status"
- sudo systemctl is-active mariadb.service
- pause
- }
- # do something in four()
- four(){
- echo "Disable Maria DB Service at boot time"
- sudo systemctl disable mariadb.service
- pause
- }
- # function to display menus
- show_menus() {
- clear
- echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
- echo " M A I N - M E N U - M A R I A - D B "
- echo " MD HARRINGTON "
- echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
- echo "1. Stop MariaDB"
- echo "2. Re Start Maria DB"
- echo "3. Check Maria DB Status"
- echo "4. Disable Maria DB Service at boot time"
- echo "5. Exit Menu "
- }
- # read input from the keyboard and take a action
- # invoke the one() when the user select 1 from the menu option.
- # invoke the two() when the user select 2 from the menu option.
- # Exit when user the user select 3 form the menu option.
- read_options(){
- local choice
- read -p "Enter choice [ 1 - 5] " choice
- case $choice in
- 1) one ;;
- 2) two ;;
- 3) three ;;
- 4) four ;;
- 5) exit 0 ;;
- *) echo -e "${RED}Error...${STD}" && sleep 2
- esac
- }
- # ----------------------------------------------
- # Step #3: Trap CTRL+C, CTRL+Z and quit singles
- # ----------------------------------------------
- trap '' SIGINT SIGQUIT SIGTSTP
- # -----------------------------------
- # Step #4: Main logic - infinite loop
- # ------------------------------------
- while true
- do
- show_menus
- read_options
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement