Advertisement
Mark2020H

Bash Script menu driven to start stop mariaDB

Oct 5th, 2020
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.28 KB | None | 0 0
  1. #!/bin/bash
  2. # MD Harrington 25-9-2020
  3. # A menu driven shell script template  for  Maria DB
  4. ## ----------------------------------
  5. # Step #1: Define variables
  6. # ----------------------------------
  7. EDITOR=Geany
  8. RED='\033[0;41;30m'
  9. STD='\033[0;0;39m'
  10.  
  11. # ----------------------------------
  12. # Step #2: User defined function
  13. # ----------------------------------
  14. pause(){
  15.   read -p "Press [Enter] key to continue..." fcnEnterKey
  16. }
  17.  
  18. one(){
  19.     echo "Stopping Maria DB Service"
  20.     sudo systemctl stop mariadb.service
  21.         pause
  22. }
  23.  
  24. # do something in two()
  25. two(){
  26.     echo "Restarting Maria DB Service "
  27.     sudo systemctl restart mariadb.service
  28.         pause
  29. }
  30. # do something in three()
  31. three(){
  32.     echo "Checking Maria DB Service Status"
  33.     sudo systemctl is-active mariadb.service
  34.         pause
  35.  
  36.  
  37.  
  38. }
  39.  
  40. # do something in four()
  41. four(){
  42.    
  43.     echo "Disable Maria DB Service at boot time"
  44.     sudo systemctl disable mariadb.service
  45.  
  46.         pause
  47.    
  48. }
  49.  
  50. # function to display menus
  51. show_menus() {
  52.     clear
  53.     echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"  
  54.     echo "   M A I N - M E N U - M A R I A - D B "
  55.     echo "            MD HARRINGTON              "
  56.     echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  57.     echo "1. Stop MariaDB"
  58.     echo "2. Re Start Maria DB"
  59.     echo "3. Check Maria DB Status"
  60.     echo "4. Disable Maria DB Service at boot time"
  61.     echo "5. Exit Menu "
  62. }
  63. # read input from the keyboard and take a action
  64. # invoke the one() when the user select 1 from the menu option.
  65. # invoke the two() when the user select 2 from the menu option.
  66. # Exit when user the user select 3 form the menu option.
  67. read_options(){
  68.     local choice
  69.     read -p "Enter choice [ 1 - 5] " choice
  70.     case $choice in
  71.         1) one ;;
  72.         2) two ;;
  73.         3) three ;;
  74.         4) four ;;
  75.         5) exit 0 ;;
  76.         *) echo -e "${RED}Error...${STD}" && sleep 2
  77.     esac
  78. }
  79.  
  80. # ----------------------------------------------
  81. # Step #3: Trap CTRL+C, CTRL+Z and quit singles
  82. # ----------------------------------------------
  83. trap '' SIGINT SIGQUIT SIGTSTP
  84.  
  85. # -----------------------------------
  86. # Step #4: Main logic - infinite loop
  87. # ------------------------------------
  88. while true
  89. do
  90.  
  91.     show_menus
  92.     read_options
  93. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement