100例SHELL脚本之六

[root@1-CentOS-7-30-LAMP ~]# cat selectmenu.sh
#!/bin/bash

###menu select######
###Dan Chen ########

######2019-6-5#######

PS3="Please input your choice: "
while :
do
select input in disk_patiton disk_use memory_use cpu_use ip_connection quit
do
case $input in
disk_patiton)
fdisk -l
break
;;
disk_use)
df -h
break
;;
memory_use)
free -m
break
;;
cpu_use)
uptime
break
;;
ip_connection)
ss -tan|grep ":80"|awk '{status[$1]++}END{for(i in status){print i,status[i]}}'
break
;;
quit)
exit
;;
*)
exit
esac
done
done

执行结果:
[root@1-CentOS-7-30-LAMP ~]# sh selectmenu.sh
1) disk_patiton 3) memory_use 5) ip_connection
2) disk_use 4) cpu_use 6) quit
Please input your choice: 1

Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00037e93

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 6555647 3072000 82 Linux swap / Solaris
/dev/sda3 6555648 209715199 101579776 83 Linux
1) disk_patiton 3) memory_use 5) ip_connection
2) disk_use 4) cpu_use 6) quit
Please input your choice: 2
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 97G 5.5G 92G 6% /
devtmpfs 903M 0 903M 0% /dev
tmpfs 912M 0 912M 0% /dev/shm
tmpfs 912M 17M 896M 2% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sr0 11G 11G 0 100% /mnt
/dev/sda1 197M 113M 84M 58% /boot
tmpfs 183M 0 183M 0% /run/user/0
1) disk_patiton 3) memory_use 5) ip_connection
2) disk_use 4) cpu_use 6) quit
Please input your choice: 3
total used free shared buff/cache available
Mem: 1823 366 180 16 1276 1199
Swap: 2999 0 2999
1) disk_patiton 3) memory_use 5) ip_connection
2) disk_use 4) cpu_use 6) quit
Please input your choice: 4
16:46:34 up 20 days, 22:19, 3 users, load average: 0.00, 0.01, 0.05
1) disk_patiton 3) memory_use 5) ip_connection
2) disk_use 4) cpu_use 6) quit
Please input your choice: 5
LISTEN 1
1) disk_patiton 3) memory_use 5) ip_connection
2) disk_use 4) cpu_use 6) quit
Please input your choice: 6


总结:本例主要考察
1.Linux下菜单的编写方法:上面是通过select+while循环+case选择菜单编写,还有一种方法是通过read+while循环编写,有兴趣的朋友可以自己做一下
2.常见的系统管理命令:有很多这里就不一一说明了,找到自己最喜欢的命令即可,这里没有做没有命令的判断有兴趣的人可以做一下。
3.命令结束后退出当前命令的使用

猜你喜欢

转载自blog.51cto.com/9447803/2405091