#!/bin/bash #show system information PS3="Your choice is: " os_check() { if [ -e /etc/redhat-release ]; then REDHAT=`cat /etc/redhat-release |cut -d' ' -f1` else DEBIAN=`cat /etc/issue |cut -d' ' -f1` fi if [ "$REDHAT" == "CentOS" -o "$REDHAT" == "Red" ]; then P_M=yum elif [ "$DEBIAN" == "Ubuntu" -o "$DEBIAN" == "ubutnu" ]; then P_M=apt-get else Operating system does not support. exit 1 fi } if [ $LOGNAME != root ]; then echo "Please use the root account operation." exit 1 fi if ! which vmstat &>/dev/null; then echo "vmstat command not found, now the install." sleep 1 os_check $P_M install procps -y echo "-----------------------------------------------------------------------" fi which iostat &>/dev/null if [ $? -ne 0 ]; then echo "iostat command not found, now the install." sleep 1 os_check $P_M install sysstat -y echo "-----------------------------------------------------------------------" fi while true; do select input in cpu_load disk_load disk_use disk_inode mem_use tcp_status cpu_top10 mem_top10 traffic quit; do case $input in cpu_load) #CPU利用率与负载 echo "---------------------------------------" i=1 while [[ $i -le 3 ]]; do echo -e "\033[32m 参考值${i}\033[0m" UTIL=`vmstat |awk '{if(NR==3)print 100-$15"%"}'` USER=`vmstat |awk '{if(NR==3)print $13"%"}'` SYS=`vmstat |awk '{if(NR==3)print $14"%"}'` IOWAIT=`vmstat |awk '{if(NR==3)print $16"%"}'` echo "Util: $UTIL" echo "User use: $USER" echo "System use: $SYS" echo "I/O wait: $IOWAIT" let i++ sleep 1 done echo "---
shell脚本监控CPU、磁盘、内存、网络流量
最新推荐文章于 2024-07-18 10:19:20 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)