Friday, November 14, 2014

Menu Driven Shell Script - Using Dialog Utility

##############################################################################
#                           MAIN STRATS HERE                                 #
##############################################################################

trap 'deletetempfiles'  EXIT     # calls deletetempfiles function on exit

while :
do

# Dialog utility to display options list

    dialog --clear --backtitle "MENU DRIVEN PROGRAM" --title "MAIN MENU" \
    --menu "Use [UP/DOWN] key to move" 12 60 6 \
    "DATE_TIME" "TO DISPLAY DATE AND TIME" \
    "CALENDAR"  "TO DISPLAY CALENDAR" \
    "DELETE"    "TO DELETE FILES" \
    "USERS"     "TO LIST CURRENTLY LOGGED IN USERS" \
    "DISK"      "TO DISPLAY DISK STATISTICS" \
    "EXIT"      "TO EXIT" 2> menuchoices.$$

    retopt=$?
    choice=`cat menuchoices.$$`

    case $retopt in

           0) case $choice in

                  DATE_TIME)  show_time ;;
                  CALENDAR)   show_cal ;;
                  DELETE)     deletefile ;;
                  USERS)      currentusers ;;
                  DISK)       diskstats ;;
                  EXIT)       clear; exit 0;;

              esac ;;

          *)clear ; exit ;;
    esac

done 
#############################################################################
 
 
 ########################## currentusers function ############################

currentusers()
{
   who > userslist.$$
   dialog --backtitle "MENU DRIVEN PROGRAM" \
   --title "CURRENTLY LOGGED IN USERS LIST" \
   --textbox userslist.$$ 12 60
}
 
##############################################################################

 
############################ diskstats function #############################

diskstats()
{
   df -h | grep "^/" > statsfile.$$
   dialog --backtitle "MENU DRIVEN PROGRAM" \
   --title "DISK STATISTICS" \
   --textbox statsfile.$$ 10 60
} 

0 comments: