Advertisement
jessicakennedy1028

Menu Driven Linux Info System

Sep 9th, 2018
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 24.82 KB | None | 0 0
  1. #!/bin/bash
  2. ####################################################################
  3. # Sathish Arthar (Sathisharthar {at} gmail.com) - Jan 2014
  4. ####################################################################
  5. # simple menu driven shell script to to get information about
  6. # your Linux server / desktop and Do some Users and File
  7. # operations Quickly.
  8. ####################################################################
  9. # REDESIGNED AND UPDATED BY JESSICA BROWN
  10. ####################################################################
  11.  
  12. # Define variables
  13. LSB=/usr/bin/lsb_release
  14.  
  15. # Purpose: Display pause prompt
  16. # $1-> Message (optional)
  17. function pause(){
  18.     local message="$@"
  19.     [ -z $message ] && message="Press [Enter] key to continue..."
  20.     read -p "$message" readEnterKey
  21. }
  22.  
  23. # Purpose - Display a menu on screen
  24. function show_menu(){
  25.     date
  26.     echo "---------------------------"
  27.     echo " Main Menu"
  28.     echo "---------------------------"
  29.     echo "1. Operating system info"
  30.     echo "2. Hostname and dns info"
  31.     echo "3. Network info"
  32.     echo "4. Who is online"
  33.     echo "5. Last logged in users"
  34.     echo "6. Free and used memory info"
  35.     echo "7. Get my ip address"
  36.     echo "8. My Disk Usage"
  37.     echo "9. Process Usage"
  38.     echo "10. Users Operations"
  39.     echo "11. File Operations"
  40.     echo "12. Exit"
  41. }
  42.  
  43. # Purpose - Display header message
  44. # $1 - message
  45. function write_header(){
  46.     local h="$@"
  47.     echo "---------------------------------------------------------------"
  48.     echo " ${h}"
  49.     echo "---------------------------------------------------------------"
  50. }
  51.  
  52. # Purpose - Get info about your operating system
  53. function os_info(){
  54.     write_header " System information "
  55.     echo "Operating system : $(uname)"
  56.     [ -x $LSB ] && $LSB -a || echo "$LSB command is not insalled (set \$LSB variable)"
  57.     #pause "Press [Enter] key to continue..."
  58.     pause
  59. }
  60.  
  61. # Purpose - Get info about host such as dns, IP, and hostname
  62. function host_info(){
  63.     local dnsips=$(sed -e '/^$/d' /etc/resolv.conf | awk '{if (tolower($1)=="nameserver") print $2}')
  64.     write_header " Hostname and DNS information "
  65.     echo "Hostname : $(hostname -s)"
  66.     echo "DNS domain : $(hostname -d)"
  67.     echo "Fully qualified domain name : $(hostname -f)"
  68.     echo "Network address (IP) : $(hostname -i)"
  69.     echo "DNS name servers (DNS IP) : ${dnsips}"
  70.     pause
  71. }
  72.  
  73. # Purpose - Network inferface and routing info
  74. function net_info(){
  75.     devices=$(netstat -i | cut -d" " -f1 | egrep -v "^Kernel|Iface|lo")
  76.     write_header " Network information "
  77.     echo "Total network interfaces found : $(wc -w <<<${devices})"
  78.     echo "*** IP Addresses Information ***"
  79.     ip -4 address show
  80.     echo "***********************"
  81.     echo "*** Network routing ***"
  82.     echo "***********************"
  83.     netstat -nr
  84.     echo "**************************************"
  85.     echo "*** Interface traffic information ***"
  86.     echo "**************************************"
  87.     netstat -i
  88.     pause
  89. }
  90.  
  91. # Purpose - Display a list of users currently logged on
  92. # display a list of receltly loggged in users
  93. function user_info(){
  94.     local cmd="$1"
  95.     case "$cmd" in
  96.         who) write_header " Who is online "; who -H; pause ;;
  97.         last) write_header " List of last logged in users "; last ; pause ;;
  98.     esac
  99. }
  100.  
  101. # Purpose - Display used and free memory info
  102. function mem_info(){
  103.     write_header " Free and used memory "
  104.     free -m
  105.     echo "*********************************"
  106.     echo "*** Virtual memory statistics ***"
  107.     echo "*********************************"
  108.     vmstat
  109.     echo "***********************************"
  110.     echo "*** Top 5 memory eating process ***"
  111.     echo "***********************************"
  112.     ps auxf | sort -nr -k 4 | head -5
  113.     pause
  114. }
  115.  
  116. # Purpose - Get Public IP address form your ISP
  117. function ip_info(){
  118.     cmd='curl -s'
  119.     write_header " Public IP information "
  120.     ipservice=checkip.dyndns.org
  121.     pipecmd=(sed -e 's/.*Current IP Address: //' -e 's/<.*$//') #using brackets to use it as an array and avoid need of scaping
  122.     $cmd "$ipservice" | "${pipecmd[@]}"
  123.     pause
  124. }
  125.  
  126. # purpose - Get Disk Usage Information
  127. function disk_info() {
  128.     usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1)
  129.     partition=$(echo $output | awk '{print $2}')
  130.  
  131.     write_header " Disk Usage Info"
  132.  
  133.     if [ "$EXCLUDE_LIST" != "" ] ; then
  134.         df -H | grep -vE "^Filesystem|tmpfs|cdrom|${EXCLUDE_LIST}" | awk '{print $5 " " $6}'
  135.     else
  136.         df -H | grep -vE "^Filesystem|tmpfs|cdrom" | awk '{print $5 " " $6}'
  137.     fi
  138.     pause
  139. }
  140.  
  141. #Purpose of Process Usage Information
  142. function proc_info() {
  143.     write_header " Process Usage Info"
  144.     txtred=$(tput setaf 1)
  145.     txtgrn=$(tput setaf 2)
  146.     txtylw=$(tput setaf 3)
  147.     txtblu=$(tput setaf 4)
  148.     txtpur=$(tput setaf 5)
  149.     txtcyn=$(tput setaf 6)
  150.     txtrst=$(tput sgr0)
  151.     COLUMNS=$(tput cols)
  152.  
  153.     center() {
  154.         w=$(( $COLUMNS / 2 - 20 ))
  155.  
  156.         while IFS= read -r line
  157.         do
  158.             printf "%${w}s %s\n" ' ' "$line"
  159.         done
  160.     }
  161.    
  162.     centerwide() {
  163.         w=$(( $COLUMNS / 2 - 30 ))
  164.         while IFS= read -r line
  165.         do
  166.             printf "%${w}s %s\n" ' ' "$line"
  167.         done
  168.     }
  169.  
  170.     while :
  171.     do
  172.         clear
  173.         echo ""
  174.         echo ""
  175.         echo "${txtcyn}(please enter the number of your selection below)${txtrst}" | centerwide
  176.         echo ""
  177.         echo "1.  Show all processes" | center
  178.         echo "2.  Kill a process" | center
  179.         echo "3.  Bring up top" | center
  180.         echo "4.  ${txtpur}Return to Main Menu${txtrst}" | center
  181.         echo "5.  ${txtred}Shut down${txtrst}" | center
  182.         echo ""
  183.         read processmenuchoice
  184.  
  185.         case $processmenuchoice in
  186.             1 )
  187.                 clear && echo "" && echo "${txtcyn}(press ENTER or use arrow keys to scroll list, press Q to return to menu)${txtrst}" | centerwide && read
  188.                 ps -ef | less
  189.                 ;;
  190.             2 )
  191.                 clear && echo "" && echo "Please enter the PID of the process you would like to kill:" | centerwide
  192.                 read pidtokill
  193.                 kill -2 $pidtokill && echo "${txtgrn}Process terminated successfully.${txtrst}" | center || echo "${txtred}Process failed to terminate. Please check the PID and try again.${txtrst}" | centerwide
  194.                 echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center && read
  195.                 ;;
  196.             3 )
  197.                 top
  198.                 ;;
  199.             4 )
  200.                 clear && echo "" && echo "Are you sure you want to return to the main menu? ${txtcyn}y/n${txtrst}" | centerwide && echo ""
  201.                 read exitays
  202.  
  203.                 case $exitays in
  204.                     y | Y )
  205.                         clear && exit
  206.                         ;;
  207.                     n | N )
  208.                         clear && echo "" && echo "Okay. Nevermind then." | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
  209.                         ;;
  210.                     * )
  211.                         clear && echo "" && echo "${txtred}Please make a valid selection.${txtrst}" | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
  212.                 esac
  213.                 ;;
  214.             5 )
  215.                 clear && echo "" && echo "Are you sure you want to shut down? ${txtcyn}y/n${txtrst}" | centerwide && echo ""
  216.                 read shutdownays
  217.  
  218.                 case $shutdownays in
  219.                     y | Y )
  220.                         clear && shutdown -h now
  221.                         ;;
  222.                     n | N )
  223.                         clear && echo "" && echo "Okay. Nevermind then." | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
  224.                         ;;
  225.                     * )
  226.                         clear && echo "" && echo "${txtred}Please make a valid selection." | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
  227.                         ;;
  228.                 esac
  229.                 ;;
  230.             * )
  231.                 clear && echo "" && echo "${txtred}Please make a valid selection." | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
  232.                 ;;
  233.         esac
  234.     done
  235.     pause
  236. }
  237.  
  238. #Purpose - For getting  User operation and infrmations
  239. function user_infos() {
  240.     write_header "User Operations"
  241.     txtred=$(tput setaf 1)
  242.     txtgrn=$(tput setaf 2)
  243.     txtylw=$(tput setaf 3)
  244.     txtblu=$(tput setaf 4)
  245.     txtpur=$(tput setaf 5)
  246.     txtcyn=$(tput setaf 6)
  247.     txtrst=$(tput sgr0)
  248.     COLUMNS=$(tput cols)
  249.  
  250.     center() {
  251.         w=$(( $COLUMNS / 2 - 20 ))
  252.         while IFS= read -r line
  253.         do
  254.             printf "%${w}s %s\n" ' ' "$line"
  255.         done
  256.     }
  257.  
  258.     centerwide() {
  259.         w=$(( $COLUMNS / 2 - 30 ))
  260.         while IFS= read -r line
  261.         do
  262.             printf "%${w}s %s\n" ' ' "$line"
  263.         done
  264.     }
  265.  
  266.     while :
  267.     do
  268.         clear
  269.         echo ""
  270.         echo ""
  271.         echo "${txtcyn}(please enter the number of your selection below)${txtrst}" | centerwide
  272.         echo ""
  273.         echo "1.  Create a user" | center
  274.         echo "2.  Change the group for a user" | center
  275.         echo "3.  Create a group" | center
  276.         echo "4.  Delete a user" | center
  277.         echo "5.  Change a password" | center
  278.         echo "6.  ${txtpur}Return to Main Menu${txtrst}" | center
  279.         echo "7.  ${txtred}Shut down${txtrst}" | center
  280.         echo ""
  281.         read usermenuchoice
  282.         case $usermenuchoice in
  283.             1 )
  284.                 clear && echo "" && echo "Please enter the new username below:  ${txtcyn}(NO SPACES OR SPECIAL CHARACTERS!)${txtrst}" | centerwide && echo ""
  285.                 read newusername
  286.                 echo "" && echo "Please enter a group for the new user:  ${txtcyn}(STILL NO SPACES OR SPECIAL CHARACTERS!)${txtrst}" | centerwide && echo ""
  287.                 read newusergroup
  288.                 echo "" && echo "What is the new user's full name?  ${txtcyn}(YOU CAN USE SPACES HERE IF YOU WANT!)${txtrst}" | centerwide && echo ""
  289.                 read newuserfullname
  290.                 echo "" && echo ""
  291.                 groupadd $newusergroup
  292.                 useradd -g $newusergroup -c "$newuserfullname" $newusername && echo "${txtgrn}New user $newusername created successfully.${txtrst}" | center || echo "${txtred}Could not create new user.${txtrst}" | center
  293.                 echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center
  294.                 read
  295.                 ;;
  296.             2 )
  297.                 clear && echo "" && echo "Which user needs to be in a different group? ${txtcyn}(USER MUST EXIST!)${txtrst}" | centerwide && echo ""
  298.                 read usermoduser
  299.                 echo "" && echo "What should be the new group for this user?  ${txtcyn}(NO SPACES OR SPECIAL CHARACTERS!)${txtrst}" | centerwide && echo ""
  300.                 read usermodgroup
  301.                 echo "" && echo ""
  302.                 groupadd $usermodgroup
  303.                 usermod -g $usermodgroup $usermoduser && echo "${txtgrn}User $usermoduser added to group $usermodgroup successfully.${txtrst}" | center || echo "${txtred}Could not add user to group. Please check if user exists.${txtrst}" | centerwide
  304.                 echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center
  305.                 read
  306.                 ;;
  307.             3 )
  308.                 clear && echo "" && echo "Please enter a name for the new group below:  ${txtcyn}(NO SPACES OR SPECIAL CHARACTERS!)${txtrst}" | centerwide && echo ""
  309.                 read newgroup
  310.                 echo "" && echo ""
  311.                 groupadd $newgroup && echo "${txtgrn}Group $newgroup created successfully.${txtrst}" | center || echo "${txtred}Failed to create group. Please check if group already exists.${txtrst}" | centerwide
  312.                 echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center
  313.                 read
  314.                 ;;
  315.             4 )
  316.                 clear && echo "" && echo "Please enter the username to be deleted below:  ${txtcyn}(THIS CANNOT BE UNDONE!)${txtrst}" | centerwide && echo ""
  317.                 read deletethisuser
  318.                 echo "" && echo "${txtred}ARE YOU ABSOLUTELY SURE YOU WANT TO DELETE THIS USER? SERIOUSLY, THIS CANNOT BE UNDONE! ${txtcyn}y/n${txtrst}" | centerwide
  319.                 read deleteuserays
  320.                 echo "" && echo ""
  321.  
  322.                 case $deleteuserays in
  323.                     y | Y )
  324.                         userdel $deletethisuser && echo "${txtgrn}User $deletethisuser deleted successfully." | center || echo "${txtred}Failed to delete user. Please check username and try again.${txtrst}" | centerwide
  325.                     ;;
  326.                     n | N )
  327.                         echo "Okay. Nevermind then." | center
  328.                     ;;
  329.                     * )
  330.                         echo "${txtred}Please make a valid selection.${txtrst}" | center
  331.                     ;;
  332.                 esac
  333.  
  334.                 echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center
  335.                 read
  336.                 ;;
  337.             5 )
  338.                 clear && echo "" && echo "Which user's password should be changed?" | centerwide
  339.                 read passuser
  340.                 echo ""
  341.                 passwd $passuser && echo "${txtgrn}Password for $passuser changed successfully.${txtrst}" | center || echo "${txtred}Failed to change password.${txtrst}" | center
  342.                 echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center
  343.                 read
  344.                 ;;
  345.             6 )
  346.                 clear && echo "" && echo "Are you sure you want to return to the main menu? ${txtcyn}y/n${txtrst}" | centerwide && echo ""
  347.                 read exitays
  348.  
  349.                 case $exitays in
  350.                     y | Y )
  351.                         clear && exit
  352.                         ;;
  353.                     n | N )
  354.                         clear && echo "" && echo "Okay. Nevermind then." | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
  355.                         ;;
  356.                     * )
  357.                         clear && echo "" && echo "${txtred}Please make a valid selection.${txtrst}" | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
  358.                         ;;
  359.                 esac
  360.                 ;;
  361.             7 )
  362.                 clear && echo "" && echo "Are you sure you want to shut down? ${txtcyn}y/n${txtrst}" | centerwide && echo ""
  363.                 read shutdownays
  364.                 case $shutdownays in
  365.                     y | Y )
  366.                         clear && shutdown -h now
  367.                         ;;
  368.                     n | N )
  369.                         clear && echo "" && echo "Okay. Nevermind then." | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
  370.                         ;;
  371.                     * )
  372.                         clear && echo "" && echo "${txtred}Please make a valid selection.${txtrst}" | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
  373.                         ;;
  374.                 esac
  375.                 ;;
  376.             * )
  377.                 clear && echo "" && echo "${txtred}Please make a valid selection.${txtrst}" | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
  378.                 ;;
  379.         esac
  380.     done
  381.     pause
  382. }
  383.  
  384. #Purpose  - For File Opertios
  385. function file_info() {
  386.     write_header "File OPerations"
  387.     txtred=$(tput setaf 1)
  388.     txtgrn=$(tput setaf 2)
  389.     txtylw=$(tput setaf 3)
  390.     txtblu=$(tput setaf 4)
  391.     txtpur=$(tput setaf 5)
  392.     txtcyn=$(tput setaf 6)
  393.     txtrst=$(tput sgr0)
  394.     COLUMNS=$(tput cols)
  395.  
  396.     center() {
  397.         w=$(( $COLUMNS / 2 - 20 ))
  398.         while IFS= read -r line
  399.         do
  400.             printf "%${w}s %s\n" ' ' "$line"
  401.         done
  402.     }
  403.  
  404.     centerwide() {
  405.         w=$(( $COLUMNS / 2 - 30 ))
  406.         while IFS= read -r line
  407.         do
  408.             printf "%${w}s %s\n" ' ' "$line"
  409.         done
  410.     }
  411.  
  412.     while :
  413.     do
  414.         clear
  415.         echo ""
  416.         echo ""
  417.         echo "${txtcyn}(please enter the number of your selection below)${txtrst}" | centerwide
  418.         echo ""
  419.         echo "1.  Create a file" | center
  420.         echo "2.  Delete a file" | center
  421.         echo "3.  Create a directory" | center
  422.         echo "4.  Delete a directory" | center
  423.         echo "5.  Create a symbolic link" | center
  424.         echo "6.  Change ownership of a file" | center
  425.         echo "7.  Change permissions on a file" | center
  426.         echo "8.  Modify text within a file" | center
  427.         echo "9.  Compress a file" | center
  428.         echo "10. Decompress a file" | center
  429.         echo "11. ${txtpur}Return to main menu${txtrst}" | center
  430.         echo "12. ${txtred}Shut down${txtrst}" | center
  431.         echo ""
  432.         read mainmenuchoice
  433.  
  434.         case $mainmenuchoice in
  435.             1 )
  436.                 clear && echo "" && echo "Current working directory:" | center && pwd | center
  437.                 echo "" && echo "Please enter the ${txtcyn}full path${txtrst} and filename for the new file:" | centerwide && echo ""
  438.                 echo "${txtcyn}(if file exists, it will be touched)${txtrst}" | center && echo ""
  439.                 read touchfile
  440.                 echo "" && echo ""
  441.                 touch $touchfile && echo "${txtgrn}File $touchfile touched successfully.${txtrst}" | centerwide || echo "${txtred}Touch failed. How did you even do that?${txtrst}" | center
  442.                 echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center && read
  443.                 ;;
  444.             2 )
  445.                 clear && echo "" && echo "Current working directory:" | center && pwd | center && echo "" && ls && echo ""
  446.                 echo "Please enter the ${txtcyn}full path${txtrst} and filename for the file to be deleted:" | centerwide && echo ""
  447.                 read rmfile
  448.                 echo "" && echo ""
  449.                 rm -i $rmfile && echo "${txtgrn}File removed successfully.${txtrst}" | center || echo "${txtred}File removal failed.${txtrst}" | center
  450.                 echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center && read
  451.                 ;;
  452.             3 )
  453.                 clear && echo "" && echo "Current working directory:" | center && pwd | center && echo "" && ls && echo ""
  454.                 echo "Please enter the ${txtcyn}full path${txtrst} for the directory to be created:" | centerwide && echo ""
  455.                 read mkdirdir
  456.                 echo "" && echo ""
  457.                 mkdir $mkdirdir && echo "${txtgrn}Directory $mkdirdir created successfully.${txtrst}" | centerwide || echo "${txtred}Failed to create directory.${txtrst}" | center
  458.                 echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center && read
  459.                 ;;
  460.             4 )
  461.                 clear && echo "" && echo "Current working directory:" | center && pwd | center && echo "" && ls && echo ""
  462.                 echo "Please enter the ${txtcyn}full path${txtrst} for the directory to be removed:  ${txtcyn}(MUST BE EMPTY!)${txtrst}" | centerwide && echo ""
  463.                 read rmdirdir
  464.                 echo "" && echo ""
  465.                 rmdir $rmdirdir && echo "${txtgrn}Directory $rmdirdir removed successfully.${txtrst}" | centerwide || echo "${txtred}Failed to remove directory. Please ensure directory is empty.${txtrst}" | centerwide
  466.                 echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center && read
  467.                 ;;
  468.             5 )
  469.                 clear && echo "" && echo "Please enter the input file for the symbolic link:  ${txtcyn}(FULL PATH!)${txtrst}" | centerwide && echo ""
  470.                 read symlinfile
  471.                 echo "" && echo "Please enter the output file for the symbolic link:  ${txtcyn}(SERIOUSLY, FULL PATH!)${txtrst}" | centerwide && echo ""
  472.                 read symloutfile
  473.                 echo "" && echo ""
  474.                 ln -s $symlinfile $symloutfile
  475.                 cat $symloutfile && clear && echo "" && echo "${txtgrn}Symbolic link created successfully at $symloutfile${txtrst}" | centerwide || echo "${txtred}Failed to create symbolic link. Please check paths and filenames and try again.${txtrst}" | centerwide && rm -f $symloutfile
  476.                 echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center && read
  477.                 ;;
  478.             6 )
  479.                 clear && echo "" && echo "Which file's ownership should be changed?  ${txtcyn}(MUST EXIST, USE FULL PATH!)${txtrst}" | centerwide && echo ""
  480.                 read chownfile
  481.                 echo "" && echo "Please enter the username for the new owner of $chownfile:  ${txtcyn}(USER MUST EXIST)${txtrst}" | centerwide && echo ""
  482.                 read chownuser
  483.                 echo "" && echo "Please enter the new group for $chownfile:  ${txtcyn}(GROUP MUST EXIST)${txtrst}" | centerwide && echo ""
  484.                 read chowngroup
  485.                 echo "" && echo ""
  486.                 chown $chownuser.$chowngroup $chownfile && echo "${txtgrn}Ownership of $chownfile changed successfully.${txtrst}" | centerwide || echo "${txtred}Failed to change ownership. Please check if user, group and file exist.${txtrst}" | center
  487.                 echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center && read
  488.                 ;;
  489.             7 )
  490.                 clear && echo "" && echo "Which file's permissions should be changed?  ${txtcyn}(MUST EXIST, USE FULL PATH!)${txtrst}" | centerwide && echo ""
  491.                 read chmodfile
  492.                 echo "" && echo "Please enter the three-digit numeric string for the permissions you would like to set:" | centerwide
  493.                 echo ""
  494.                 echo "${txtcyn}( format is [owner][group][all]  |  ex: ${txtrst}777${txtcyn} for full control for everyone )${txtrst}" | centerwide
  495.                 echo ""
  496.                 echo "${txtcyn}4 = read${txtrst}" | center
  497.                 echo "${txtcyn}2 = write${txtrst}" | center
  498.                 echo "${txtcyn}1 = execute${txtrst}" | center
  499.                 echo ""
  500.                 read chmodnum
  501.                 echo "" && echo ""
  502.                 chmod $chmodnum $chmodfile && echo "${txtgrn}Permissions for $chmodfile changed successfully.${txtrst}" | centerwide || echo "${txtred}Failed to set permissions.${txtrst}" | center
  503.                 echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center && read
  504.                 ;;
  505.             8 )
  506.                 clear && echo "" && echo "Please enter the full path and filename for the file you wish to edit:" | centerwide && echo ""
  507.                 read editfile
  508.                 echo "Which program would you like to use to edit this file?" | centerwide && echo ""
  509.                 echo "${txtcyn}(please enter the number of your selection below)${txtrst}" | centerwide
  510.                 echo "1. vim" | center
  511.                 echo "2. nano" | center
  512.                 echo "3. mcedit" | center
  513.                 echo "4. emacs" | center
  514.                 echo "5. pico" | center
  515.                 echo ""
  516.                 read editapp
  517.                 echo ""
  518.                
  519.                 case $editapp in
  520.                     1 )
  521.                         vim $editfile || echo "${txtred}Failed to open vim. Please check if it is installed.${txtrst}" | centerwide
  522.                         ;;
  523.                     2 )
  524.                         nano $editfile || echo "${txtred}Failed to open nano. Please check if it is installed.${txtrst}" | centerwide
  525.                         ;;
  526.                     3 )
  527.                         mcedit $editfile || echo "${txtred}Failed to open mcedit. Please check if it is installed.${txtrst}" | centerwide
  528.                         ;;
  529.                     4 )
  530.                         emacs $editfile || echo "${txtred}Failed to open emacs. Please check if it is installed.${txtrst}" | centerwide
  531.                         ;;
  532.                     5 )
  533.                         pico $editfile || echo "${txtred}Failed to open pico. Please check if it is installed.${txtrst}" | centerwide
  534.                         ;;
  535.                     * )
  536.                         echo "${txtred}Please make a valid selection.${txtrst}" | center
  537.                         ;;
  538.                 esac
  539.                 echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center && read
  540.                 ;;
  541.             9 )
  542.                 clear && echo "" && echo "Please enter the ${txtcyn}full path${txtrst} and filename for the file you wish to compress:" | centerwide && echo ""
  543.                 read pressfile
  544.                 echo "" && echo "Which method of compression would you like to use?" | centerwide && echo ""
  545.                 echo "${txtcyn}(please enter the number of your selection below)${txtrst}" | centerwide
  546.                 echo ""
  547.                 echo "1. gzip" | center
  548.                 echo "2. bzip2" | center
  549.                 echo "3. compress" | center
  550.                 echo ""
  551.                 read pressmethod
  552.                 echo ""
  553.                 case $pressmethod in
  554.                     1 )
  555.                         gzip $pressfile && echo "${txtgrn}File compressed successfully.${txtrst}" | center || echo "${txtred}File failed to compress.${txtrst}" | center
  556.                         ;;
  557.                     2 )
  558.                         bzip2 $pressfile && echo "${txtgrn}File compressed successfully.${txtrst}" | center || echo "${txtred}File failed to compress.${txtrst}" | center
  559.                         ;;
  560.                     3 )
  561.                         compress $pressfile && echo "${txtgrn}File compressed successfully.${txtrst}" | center || echo "${txtred}File failed to compress.${txtrst}" | center
  562.                         ;;
  563.                     * )
  564.                         echo "${txtred}Please make a valid selection.${txtrst}" | center
  565.                         ;;
  566.                 esac
  567.                 echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center && read
  568.                 ;;
  569.             10 )
  570.                 clear && echo "" && echo "Please enter the ${txtcyn}full path${txtrst} and filename for the file you wish to decompress:" | centerwide && echo ""
  571.                 read depressfile
  572.  
  573.                 case $depressfile in
  574.                     *.gz | *.GZ )
  575.                         gunzip $depressfiles && echo "${txtgrn}File decompressed successfully.${txtrst}" | center || echo "${txtred}File failed to decompress.${txtrst}" | center
  576.                         ;;
  577.                     *.bz2 | *.BZ2 )
  578.                         bunzip2 $depressfile && echo "${txtgrn}File decompressed successfully.${txtrst}" | center || echo "${txtred}File failed to decompress.${txtrst}" | center
  579.                         ;;
  580.                    
  581.                     *.z | *.Z )
  582.                         uncompress $depressfile && echo "${txtgrn}File decompressed successfully.${txtrst}" | center || echo "${txtred}File failed to decompress.${txtrst}" | center
  583.                         ;;
  584.                    
  585.                     * )
  586.                         echo "${txtred}File does not appear to use a valid compression method (gzip, bzip2, or compress). Please decompress manually.${txtrst}" | centerwide
  587.                 esac
  588.  
  589.                 echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center && read
  590.                 ;;
  591.             11 )
  592.                 clear && echo "" && echo "Are you sure you want to return to the main menu? ${txtcyn}y/n${txtrst}" | centerwide && echo ""
  593.                 read exitays
  594.    
  595.                 case $exitays in
  596.                     y | Y )
  597.                         clear && exit
  598.                     ;;
  599.                     n | N )
  600.                         clear && echo "" && echo "Okay. Nevermind then." | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
  601.                     ;;
  602.                     * )
  603.                         clear && echo "" && echo "${txtred}Please make a valid selection.${txtrst}" | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
  604.                 esac
  605.                 ;;
  606.             12 )
  607.                 clear && echo "" && echo "Are you sure you want to shut down? ${txtcyn}y/n${txtrst}" | centerwide && echo ""
  608.                 read shutdownays
  609.    
  610.                 case $shutdownays in
  611.                     y | Y )
  612.                         clear && shutdown -h now
  613.                     ;;
  614.                     n | N )
  615.                         clear && echo "" && echo "Okay. Nevermind then." | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
  616.                     ;;
  617.                     * )
  618.                         clear && echo "" && echo "${txtred}Please make a valid selection.${txtrst}" | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
  619.                     ;;
  620.                 esac
  621.                 ;;
  622.             * )
  623.                 clear && echo "" && echo "${txtred}Please make a valid selection.${txtrst}" | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
  624.                 ;;
  625.         esac
  626.     done
  627.     pause
  628. }
  629.  
  630. # Purpose - Get input via the keyboard and make a decision using case..esac
  631. function read_input(){
  632.     local c
  633.     read -p "Enter your choice [ 1 -12 ] " c
  634.     case $c in
  635.         1) os_info ;;
  636.         2) host_info ;;
  637.         3) net_info ;;
  638.         4) user_info "who" ;;
  639.         5) user_info "last" ;;
  640.         6) mem_info ;;
  641.         7) ip_info ;;
  642.         8) disk_info ;;
  643.         9) proc_info ;;
  644.         10) user_infos ;;
  645.         11) file_info ;;
  646.         12) echo "Bye!"; exit 0 ;;
  647.         *)
  648.             echo "Please select between 1 to 12 choice only."
  649.             pause
  650.             ;;
  651.     esac
  652. }
  653.  
  654. # ignore CTRL+C, CTRL+Z and quit singles using the trap
  655. trap '' SIGINT SIGQUIT SIGTSTP
  656.  
  657. # main logic
  658. while true
  659. do
  660.     clear
  661.     show_menu # display memu
  662.     read_input # wait for user input
  663. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement