Script Requirements:
After executing the script
Accepts input 1, displays the current time, and prompts you to continue the selection.
Accepts input 2, displays the CPU load, and prompts you to continue the selection.
Accepts input 3, displays the remaining memory, and prompts you to continue the selection.
Accept input 0 and exit the script.
·····················································································································
Ideas:
Show Current Time
[Email protected] ~]# date +%t
08:26:04
························································································································· ·······················································································
Uptime command can show 1) current system time;
2) The machine has been running time;
3) The current system has several user connections;
4) The average load of the system for the last 1 minutes, 5 minutes, 15 minutes of the machine.
As follows:
We can use awk to select the output of the uptime output.
························································································································· ···························································································
The FREE-M command can display memory usage in M, as well as swap partition swap usage, using awk to print out the information in the 4th column of the Mem line, which is the information we want.
························································································································· ·····························································································
As for whether to continue the selection, you can use the while loop. The final script is as follows:
1#!/bin/Bash2 #3 while["1"=="1" ]4 Do5 Clear6 Echo "~~~~~~~~~~~~~~~~~~~menu~~~~~~~~~~~~~~~~~~~~~~"7 Echo "1) time now"8 Echo "2) CPU Load"9 Echo "3) Memory free"Ten Echo "0) Exit" One Echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" A Echo "Please enter a chose[0~3]:" - Read NUM - Case${num}inch the 1)Echo "Time now : ' Date +%t '" ;; - 2)Echo "CPU Load: ' Uptime |awk-f ' [:,] ' {print $6} '" ;; - 3)Echo "Memory Free: ' free-m |awk ' $1=="Mem:"{print $4} ' m" ;; - 0) exit;; +*)Echo "This chose was not in [0~3]." - Esac + Echo-N"Do you continue [y/n]:" A Read Continue at if["${contiune}"=="N"-O"${continue}"=="N" ] - Then - Exit - fi - Done
Scripting of Shell Learning 1