Useful menu structure.
Nicely used when bash is not around, and you need some interactive menu.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
#!/bin/sh # sample.mnu # A simple script menu under Unix # Main logic starts at MAIN LOGIC # The logo will be displayed at the top of the screen LOGO="Oracle info report Menu - Marc Riera (Bull 2012)" #------------------------------------------------------ # MENU PROMPTS #------------------------------------------------------ # A list of menu prompts to be displayed for the user. # The list can be modified. # In this first list, enter the menu prompt as it should appear # on the screen for each of the letters A - L. In this example # menu pick variables emenu through lmenu are blank as there # are no menu selections for keys E through L. amenu="a. whoami.sql : rem Purpose: Reports information about your current database context"; bmenu="b. ver.sql : rem Purpose: Show database version with options intalled"; cmenu="c. usedsp.sql : rem Purpose: Used space in Meg by segment type"; dmenu="d. datos_generals.sql : rem Purpose: General info about the connected database"; emenu="e. version_bbdd.sql : rem Purpose: Display v\$version database "; fmenu="f. tablespaces_size_free_percent2.sql : rem Purpose: Tablespaces size free percent 2 "; gmenu="g. redologs_status.sql : rem Purpose: Redologs status"; hmenu="h. datafile_size_free_percent.sql : rem Purpose: Datafile size free percent "; imenu="i. control_file.sql : rem Purpose: Control files"; jmenu="j. nls_parameters.sql : rem Purpose: Nls parameters "; kmenu="k. db_options.sql : rem Purpose: Database options "; lmenu=" " ; mmenu="m Payroll Menu " ; #------------------------------------------------------ # MENU FUNCTION DEFINITIONS #------------------------------------------------------ # Define a function for invalid menu picks # The function loads an error message into a variable badchoice () { MSG="Invalid Selection ... Please Try Again" ; } # For each prompt displayed above, there is a list of # commands to execute in response to the user picking the # associated letter. # They are defined as functions # apick () through lpick () where # apick () corresponds to the menu # prompt amenu which is selected # selected by pressing a or A. # bpick () corresponds to the menu # prompt bmenu which is selected by # pressing b or B and so on. # Any menu item that is not # assigned a set of commands, is # assigned # the function badchoice () as a default for that pick. # If the user # selects a menu key that is assigned # to badchoice (). This function # causes an error message to be # displayed on the screen. # To add items to this second # list, replace badchoice () # with the commands to run when # that letter is pressed. # The following steps simply define # the functions, but do not cause # any shell program steps to be executed. # Command example : sqlplus -S sys/gonna@bi as sysdba @ask_version.sql apick () { sqlplus -S sys/<YOURPASSHERE>@<INSTANCE> as sysdba @whoami.sql ; echo Press Enter ; read DUMMY ; } bpick () { sqlplus -S sys/<YOURPASSHERE>@<INSTANCE> as sysdba @ver.sql; echo Press Enter ; read DUMMY ; } cpick () { sqlplus -S sys/<YOURPASSHERE>@<INSTANCE> as sysdba @usedsp.sql; echo Press Enter ; read DUMMY ; } dpick () { sqlplus -S sys/<YOURPASSHERE>@<INSTANCE> as sysdba @datos_generals.sql; echo Press Enter ; read DUMMY ; } epick () { sqlplus -S sys/<YOURPASSHERE>@<INSTANCE> as sysdba @version_bbdd.sql; echo Press Enter ; read DUMMY ; } fpick () { sqlplus -S sys/<YOURPASSHERE>@<INSTANCE> as sysdba @tablespaces_size_free_percent2.sql; echo Press Enter ; read DUMMY ; } gpick () { sqlplus -S sys/<YOURPASSHERE>@<INSTANCE> as sysdba @redologs_status.sql; echo Press Enter ; read DUMMY ; } hpick () { sqlplus -S sys/<YOURPASSHERE>@<INSTANCE> as sysdba @datafile_size_free_percent.sql; echo Press Enter ; read DUMMY ; } ipick () { sqlplus -S sys/<YOURPASSHERE>@<INSTANCE> as sysdba @control_file.sql; echo Press Enter ; read DUMMY ; } jpick () { sqlplus -S sys/<YOURPASSHERE>@<INSTANCE> as sysdba @nls_parameters.sql ; echo Press Enter ; read DUMMY ; } kpick () { sqlplus -S sys/<YOURPASSHERE>@<INSTANCE> as sysdba @db_options.sql ; echo Press Enter ; read DUMMY ; } lpick () { badchoice ; } mpick () { payroll.mnu ; } #------------------------------------------------------ # DISPLAY FUNCTION DEFINITION #------------------------------------------------------ # This function displays the menu. # The routine clears the screen, echoes # the logo and menu prompts # and some additional messages. # Note that this definition does # not cause the function to # be executed yet, it just defines # it ready to be executed. themenu () { # clear the screen clear echo `date` echo echo "\t\t\t" $LOGO echo echo "\t\tPlease Select:" echo echo "\t\t\t" $amenu echo "\t\t\t" $bmenu echo "\t\t\t" $cmenu echo "\t\t\t" $dmenu echo "\t\t\t" $emenu echo "\t\t\t" $fmenu echo "\t\t\t" $gmenu echo "\t\t\t" $hmenu echo "\t\t\t" $imenu echo "\t\t\t" $jmenu echo "\t\t\t" $kmenu echo "\t\t\t" $lmenu echo "\t\t\tx. Exit" echo echo $MSG echo echo Select by pressing the letter and then ENTER ; } #------------------------------------------------------ # MAIN LOGIC #------------------------------------------------------ # Every thing up to this point has been to define # variables or functions. # The program actually starts running here. # Clear out the error message variable MSG= # Repeat the menu over and over # Steps are: # 1. Display the menu # 2. 'read' a line of input from the key board # 3. Clear the error message # 4. Check the answer for a or A or b or B etc. and dispatch # to the appropriate program or function or exit # 5. If the entry was invalid call the badchoice () function # to initialize MSG to an error message # 6. This error message is used when setting up the menu # for a menu pick that is valid but has no command # associated with it. while true do # 1. display the menu themenu # 2. read a line of input from the keyboard read answer # 3. Clear any error message MSG= # 4. Execute one of the defined functions based on the # letter entered by the user. # 5. If the choice was E through L, the pre-defined # function for that pick will execute badchoice () # which loads an error message into MSG case $answer in a|A) apick;; b|B) bpick;; c|C) cpick;; d|D) dpick;; e|E) epick;; f|F) fpick;; g|G) gpick;; h|H) hpick;; i|I) ipick;; j|J) jpick;; k|K) kpick;; l|L) lpick;; # If the user selects =91x=92 to exit then break out # of this loop x|X) break;; # 6. If the entry was invalid call the badchoice function # to initialize MSG to an error message *) badchoice;; esac # Do it again until the user enters =91x=92. done exit 0 |