Six of the 100 cases SHELL script

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

select menu ### ######
### ######## 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


Summary: in this case mainly on the
lower 1.Linux menu preparation method: The above is by select + while loop + case selection menu to write, there is a way through read + while loop write, interested friends can do something
2. common system administration commands: there are many here not setting them up, find your favorite commands can be, there is no command do not judge those who are interested in what can be done.
3. Quit command after the end of the current command

Guess you like

Origin blog.51cto.com/9447803/2405091