#!/bin/bash
echo "
220.181.38.148
58.250.137.36
eisc.cn
" > iplist.txt
port=22 # 定义测试IP的端口
for ip in `cat iplist.txt`;do # for循环,定义变量IP 是 in 赋值为一条命令 查看文件的结果, do 开始循环
telnet $ip $port>/dev/null #先检查主机是否在线,如果在线则进行进一步监控
if [ $? -eq 0 ];then # 判断 $? 上一条命令成功执行后 then 然后
rootused=``ssh $ip df -h|grep /$|awk '{print $4}'|cut -d% -f1` #取根目录使用情况
for hardid in ``ssh $ip df -h|grep "^\/dev\/s[a-z][a-z]"|awk '{print $1}'`;do
hardused=``ssh $ip df -h|grep $hardid|awk '{print $5}'|cut -d% -f1` #取其它本地硬盘的使用情况
done # 结束循环
memtotal=`ssh $ip free -m|grep Mem|awk '{print $2}'`
memused=`ssh $ip free -m|grep Mem|awk '{print $3}'`
mem=`expr $memused \* 100 / $memtotal`
idelcpu=`ssh $ip top -n1|grep Cpu|awk '{print $5}'|cut -d"." -f1`
cpuused=`expr 100 - $idelcpu`
if [ $mem -gt 70 ];then #如果内存使用高于70%则邮件通知
echo "warm:$ip memory is $mem"|mutt -s "monitor report" xxx@eisc.cn
fi
if [ $hardused -le 80 ];then #如果硬盘使用已高于80%则邮件通知
echo "warm:$ip the Hard drive capacity is more 80%"|mutt -s"monitor report" xxx@eisc.cn
fi
if [ $rootused -le 80 ];then #如果硬盘使用已高于80%则邮件通知
echo "warm:$ip the Hard drive capacity is more 80%"|mutt -s"monitor report" xxx@eisc.cn
fi
for hardid in `ssh $ip iostat |grep "^s[a-z][a-z]"|awk '{print $1}'`;do #先取盘符
iostat=`ssh $ip iostat -x|grep $hardid|awk '{print $12}'|cut -d"." -f1` #取得io繁忙状态
echo $iostat
if [ $iostat -gt 80 ];then #如果io繁忙高于80%,则邮件通知
echo "ipaddress:$ip,hard:$hardid,iostat:$iostat"|mutt -s"warm" xxx@eisc.cn
fi
done
else
echo "host:$ip is not alive"|mutt -s"monitor report" xxx@eisc.cn #如果主机无法ping通则邮件通知
fi
done
Powered by ddoss.cn 12.0
©2015 - 2025 ddoss
渝公网安备50011302222260号
渝ICP备2024035333号
【实验平台安全承诺书】
小绿叶技术社区,优化网络中,点击查看配置信息
主机监控系统: 安全防火墙已开启检查cc攻击-下载文件完成后等待10s 恢复访问,检查连接数低于峰值恢复访问
您的IP:216.73.216.110,2025-12-01 16:05:44,Processed in 0.01794 second(s).