Practice A
1. Write a script
1) display a menu to the user
d| D) show disk usages.
m| M) show memory usages.
s| S) show swap usages.
*) quit.
2) Display the appropriate content when the user has given the option:
Extended:
When the user chooses to complete, displays the corresponding information, does not exit, but lets the user select again, again
Displays the appropriate content, except that the user uses quit.
#!/bin/bash
#program:
#练习磁盘管理相关脚本编写
#history Donggen 2016-11-03-10:19
Path=http://www.11.qixoo.com/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bash
Export PATH
Cat << EOF
d| D) show disk usages.
m| M) show memory usages.
s| S) show swap usages.
*) quit.
Eof
Read-p "Your Choice:" Choice
while [$CHOICE! = "Quit"]; Do
Case $CHOICE in
d| D
DF-PH;;
m| M
Free-m;;
s| S
free-m | grep ' Swap ';;
*)
echo "Unknown ...";;
Esac
Read-p "Again,your Choice:" Choice
Done
[test]#./showsystem.sh
d| D) show disk usages.
m| M) show memory usages.
s| S) show swap usages.
*) quit.
Your choice:d
Filesystem Size used Avail use% mounted on
/dev/sda2 4.9G 1.5G 3.1G 33%/
Tmpfs 947M 0 947M 0%/dev/shm
/DEV/SDA1 2.0G 61M 1.8G 4%/boot
/dev/sda3 3.9G 73M 3.6G 2%/Home
/dev/sda7 2.0G 35M 1.8G 2%/tmp
/dev/sda5 2.9G 1.7G 1.2G 59%/usr
Again,your choice:d
Filesystem Size used Avail use% mounted on
/dev/sda2 4.9G 1.5G 3.1G 33%/
Tmpfs 947M 0 947M 0%/dev/shm
/DEV/SDA1 2.0G 61M 1.8G 4%/boot
/dev/sda3 3.9G 73M 3.6G 2%/Home
/dev/sda7 2.0G 35M 1.8G 2%/tmp
/dev/sda5 2.9G 1.7G 1.2G 59%/usr
Again,your choice:s
swap:1999 0 1999
Again,your choice:n
Unknown.
Again,your choice:m
Total used free shared buffers Cached
mem:1893 181 1711 0 42 62
-/+ buffers/cache:76 1816
swap:1999 0 1999
Again,your Choice:quit
[test]#
Linux command exercise: Disk Management related Exercises