#!/usr/bin/bash
source /etc/init.d/functions
help_menu(){
cat <<-EOF
d、顯示磁盤利用率
m、顯示內存利用率
u、顯示CPU負載狀況
a、顯示IP地址
b、顯示磁盤分區
n、顯示網絡狀況
h、顯示命令幫助
EOF
}bash
cat <<-EOF d、顯示磁盤利用率 m、顯示內存利用率 u、顯示CPU負載狀況 a、顯示IP地址 b、顯示磁盤分區 n、顯示網絡狀況 h、顯示命令幫助 EOF while true do trap "" HUP INT TSTP read -p "請輸入要查看的功能編號:[h顯示幫助]" num case $num in d) clear df -Th #break ;; m) clear free -m #break ;; u) clear uptime #break ;; a) clear ifconfig #break ;; b) clear blkid #break ;; n) clear ping -c 1 www.baidu.com &> /dev/null if [ $? -eq 0 ];then action "網絡環境" /bin/true else action "網絡環境" /bin/false fi #break ;; h) clear help_menu #break ;; exec) exit 1 break ;; *) echo "ERROR" esac done
執行結果:
[root@zt94886 day01]# sh sys_tool.sh
d、顯示磁盤利用率
m、顯示內存利用率
u、顯示CPU負載狀況
a、顯示IP地址
b、顯示磁盤分區
n、顯示網絡狀況
h、顯示命令幫助
請輸入要查看的功能編號:[h顯示幫助]d
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda1 ext4 40G 1.8G 36G 5% /
devtmpfs devtmpfs 909M 0 909M 0% /dev
tmpfs tmpfs 920M 0 920M 0% /dev/shm
tmpfs tmpfs 920M 472K 919M 1% /run
tmpfs tmpfs 920M 0 920M 0% /sys/fs/cgroup
tmpfs tmpfs 184M 0 184M 0% /run/user/0
請輸入要查看的功能編號:[h顯示幫助]h
d、顯示磁盤利用率
m、顯示內存利用率
u、顯示CPU負載狀況
a、顯示IP地址
b、顯示磁盤分區
n、顯示網絡狀況
h、顯示命令幫助
請輸入要查看的功能編號:[h顯示幫助]m
total used free shared buff/cache available
Mem: 1838 77 1048 0 712 1591
Swap: 0 0 0
請輸入要查看的功能編號:[h顯示幫助]h
d、顯示磁盤利用率
m、顯示內存利用率
u、顯示CPU負載狀況
a、顯示IP地址
b、顯示磁盤分區
n、顯示網絡狀況
h、顯示命令幫助
請輸入要查看的功能編號:[h顯示幫助]b
/dev/vda1: UUID="1114fe9e-2309-4580-b183-d778e6d97397" TYPE="ext4"
請輸入要查看的功能編號:[h顯示幫助]h
d、顯示磁盤利用率
m、顯示內存利用率
u、顯示CPU負載狀況
a、顯示IP地址
b、顯示磁盤分區
n、顯示網絡狀況
h、顯示命令幫助
請輸入要查看的功能編號:[h顯示幫助]n
網絡環境 [ OK ]
請輸入要查看的功能編號:[h顯示幫助]網絡
初學Linux,寫的腳本不免有錯誤之處,請你們多多指正,謝謝!ide