Shell writing system Gadgets

! # / usr / bin / the bash
Source /etc/init.d/functions
HELP_MENU () {
CAT << - the EOF
D, display disk utilization
m, display memory utilization
u, CPU load display
a, the IP address
b display disk partition
n, shows the network situation
h, display command help
EOF
}

    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

Results of:
[@ zt94886 the root day01] # SH sys_tool.sh
D, display disk utilization
m, display memory utilization
u, CPU load display
a, the IP address
b, display partition
n, shows the network where
h, display command to help
enter the function number you want to see: [h display help] d
Filesystem Type Size Used Avail the Use% Mounted ON
/ dev / Vdal 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 / the User / 0
function enter to view numbers: [h display help] H
D, display disk utilization
m, display memory utilization
u, CPU load display
a, the IP address
b, display partition
n, shows the network where
h, display command help
enter function to view ID: [h display help] m
Free Shared BUFF Used Total / Cache Available
Mem: 1838 712 1591 77 1048 0
Swap: 0 0 0
Please enter a number to view features: [h Display help] H
D, display disk utilization
m, display memory utilization
u, display CPU load
a, the IP address
b, show disk partitions
n, shows the network situation
h, display command to help
enter the function number you want to see: [h display help] b
/ dev / Vdal: UUID = "1114fe9e-2309-4580 -b183-d778e6d97397 "TYPE =" ext4 "
Please enter a number to view features: [h display help] H
D, display disk utilization
m, display memory utilization
u, CPU load display
a, the IP address
b, show partition
n, shows the network situation
h, display command to help
enter the function number you want to see: [h display help] n
the network environment [OK]
enter the function number you want to see: [h display help]


Beginner Linux, written in the script is inevitable mistakes, please correct me, thank you!

Guess you like

Origin blog.51cto.com/14648383/2467606