shell脚本监控CPU

vim aa.sh

借助 vmstat 工具来分析 CPU 统计信息。

#!/bin/bash 
DATE=$(date +%F" "%H:%M) 
IP=$(ifconfig eth0 |awk -F '[ :]+' '/inet addr/{print $4}')  # 只支持 CentOS6 
MAIL="[email protected]" 
if ! which vmstat &>/dev/null; then
     echo "vmstat command no found, Please install procps package."
     exit 1 
fi 
US=$(vmstat |awk 'NR==3{print $13}') 
SY=$(vmstat |awk 'NR==3{print $14}') 
IDLE=$(vmstat |awk 'NR==3{print $15}') 
WAIT=$(vmstat |awk 'NR==3{print $16}') 
USE=$(($US+$SY)) 
if [ $USE -ge 50 ]; then
     echo "
     Date: $DATE     
     Host: $IP     
     Problem: CPU utilization $USE     
     " | mail -s "CPU Monitor" $MAIL 
fi
sh aa.sh
发布了35 篇原创文章 · 获赞 11 · 访问量 2958

猜你喜欢

转载自blog.csdn.net/weixin_45697805/article/details/103455316