本文共 2950 字,大约阅读时间需要 9 分钟。
#!/usr/bin/bash
echo "##########关于cpu##########"vmstat &>/dev/nullif [ $? -ne 0 ];thenecho "vmstat command is not found,please install it!"yum install -y procpsecho "命令已安装!请重新执行该命令"exit 0fi#us 用户使用cpu花费时间; sy 系统使用cpu花费时间;id cpu空闲时间id=us+sy;wa cpu耗费等待io上时间cpu_us=vmstat | awk '{print $13}' | sed -n '$p'
cpu_sy=vmstat | awk '{print $14}' | sed -n '$p'
cpu_id=vmstat | awk '{print $15}' | sed -n '$p'
cpu_wa=vmstat | awk '{print $16}' | sed -n '$p'
cpu_sum=$(($cpu_us+$cpu_sy))echo "cpu空闲时间(id):$cpu_id"echo "cpu等待时间:"$cpu_wa#!/usr/bin/bashecho "##########关于cpu##########"vmstat &>/dev/nullif [ $? -ne 0 ];thenecho "vmstat command is not found,please install it!"yum install -y procpsecho "命令已安装!请重新执行该命令"exit 0fi#us 用户使用cpu花费时间; sy 系统使用cpu花费时间;id cpu空闲时间id=us+sy;wa cpu耗费等待io上时间cpu_us=vmstat | awk '{print $13}' | sed -n '$p'
cpu_sy=vmstat | awk '{print $14}' | sed -n '$p'
cpu_id=vmstat | awk '{print $15}' | sed -n '$p'
cpu_wa=vmstat | awk '{print $16}' | sed -n '$p'
cpu_sum=$(($cpu_us+$cpu_sy))echo "cpu空闲时间(id):$cpu_id"echo "cpu等待时间:"$cpu_waecho "cpu 总共用时(us+sy): $cpu_sum"if [ $cpu_sum -ge 70 ];thenecho "your cpu utilization is $cpu_sum."|mail -s "cpu utilization" 838021892@qq.comfiecho "###########关于内存#############"free &>/dev/nullif [ $? -ne 0 ];thenecho "free command is not found,please install it!"exit 0fimemory=free -m|grep Mem|awk '{print "使用的内存:"$2"M,还剩余内存"$3"M,所以内存使用率为:"$3/$2*100"%"}'
echo $memorymemory_1=free -m|grep Mem|awk '{print ""$3/$2*100""}'
if [ $? -ge 80 ];thenecho "your memory utilization is $memory_1"|mail -s "memory error" 838021892@qq.comfiecho "#############关于磁盘############"df &>/dev/nullif [ $? -ne 0 ];thenecho "free command is not found,please install it!"exit 0fidisk_0=df -h|sed -n '3,5p'|awk '{print $(NF-1)}'
disk=df -h|sed -n '3,5p'|awk '{print $(NF-1)}'|cut -b 1
echo $disk_0for i in $diskdoif [ $i -ge 70 ];thenecho "your disk utilization is %i"|mail -s "disk error" 838021892@qq.comfidoneecho "cpu 总共用时(us+sy): $cpu_sum"if [ $cpu_sum -ge 70 ];thenecho "your cpu utilization is $cpu_sum."|mail -s "cpu utilization" 838021892@qq.comfiecho "###########关于内存#############"free &>/dev/nullif [ $? -ne 0 ];thenecho "free command is not found,please install it!"exit 0fimemory=free -m|grep Mem|awk '{print "使用的内存:"$2"M,还剩余内存"$3"M,所以内存使用率为:"$3/$2*100"%"}'
echo $memorymemory_1=free -m|grep Mem|awk '{print ""$3/$2*100""}'
if [ $? -ge 80 ];thenecho "your memory utilization is $memory_1"|mail -s "memory error" 838021892@qq.comfiecho "#############关于磁盘############"df &>/dev/nullif [ $? -ne 0 ];thenecho "free command is not found,please install it!"exit 0fidisk_0=df -h|sed -n '3,5p'|awk '{print $(NF-1)}'
disk=df -h|sed -n '3,5p'|awk '{print $(NF-1)}'|cut -b 1
echo $disk_0for i in $diskdoif [ $i -ge 70 ];thenecho "your disk utilization is %i"|mail -s "disk error" 838021892@qq.comfidone 转载于:https://blog.51cto.com/13475803/2059357