远程硬盘资源监控通用脚本
来源:互联网 发布:网络语言的利弊作文 编辑:程序博客网 时间:2024/04/30 10:09
一、建立一个通用shell脚本,通过ssh执行df命名获取对端硬盘信息。注意增加执行权限。
[iptv@ting-wo disk]$ more diskmonitor.sh
#!/bin/bash
mailflag="true"
#check parameters count
if [ $# -ne 6 ];then
echo 6 parameters needed:taskname client_ip_list port account maillist alertlimit
echo example:diskmonitor.sh iptvservers 10.17.44.122 22 iptv abc@aaa.com 3
echo \"3\" at the ednd means it will send alert mail if disk usage > 30%. 3表示超过30%就告警。
return 1;
fi;
if [[ ! $6 =~ ^[0-9]$ ]];then
echo "\$6 is the lowest limit of triger alert,must be a number and between 1-9."
return 1;
fi;
echo "**********start**********"
taskname=$1
client_ip_list=$2
dir="/home/iptv/monitor/disk"
logfile=${dir}/disk${taskname}.log
mailfile=${dir}/mail${taskname}.txt
port=$3
account=$4
maillist=$5
limit=$6
date
echo taskname=$taskname,client_ip_list=$client_ip_list,port=$port,account=$account,maillist=$maillist
#echo "clean tmp file"
#cat /dev/null > $mailfile;
#cat /dev/null > $logfile;
#count ,how many disks > 30%;
for ip in ${client_ip_list};do
echo "#####start looking ${ip}\'s disk info.#####"
cat /dev/null > $mailfile;
cat /dev/null > $logfile;
echo ssh get disks info to $logfile
ssh -p${port} ${account}@${ip} df -h > $logfile;
if [ $? -ne 0 ];then
echo ssh error.exit loop.;
break;
fi;
count=`cat $logfile| grep -v mnt|grep -c -E [${limit}-9][0-9]%\|100%`;
echo disk alert count=$count
if [ $count -gt 0 ];
then
echo "start alerting by mail......"
echo "This is a alert for ${ip}\'s disk usage." >> $mailfile
echo "host address:${ip}" >> $mailfile
echo "disk info:" >> $mailfile
cat $logfile >> $mailfile
if [ "$mailflag" == "true" ]; then
for mail in $maillist;do
mail -s "disk alert for ${ip}" $mail < $mailfile;
done;
fi;
fi;
echo "#####end ${ip}#####"
done;
echo "*********end*********"
二、建立一个专用shell脚本,调用通用脚本。注意增加执行权限。
[iptv@ting-wo disk]$ more disk158.sh
#!/bin/bash
maillist="aaa@1234.com bbb@1234.com"
taskname=158
client_ip_list="11.22.33.158"
account=nginx
port=22
limit=3
#password=nginxUser*1
/home/iptv/monitor/disk/diskmonitor.sh "$taskname" "$client_ip_list" "$port" "$account" "$maillist" "$limit"
三、在cron中加入定期任务
0 6 * * * /home/iptv/monitor/disk/disk158.sh > /home/iptv/monitor/disk/crondisk158.log 2>&1
四、设置ssh对端免密码登录,略。
- 远程硬盘资源监控通用脚本
- linux服务器硬盘监控-shell脚本
- java远程监控linux资源情况
- loadrunner监控资源添加远程机器失败
- Shell脚本监控Linux系统硬盘各分区使用率
- 硬盘监控
- 通用的进程监控重拉起bash脚本
- 通用的进程监控重拉起bash脚本
- 通用的进程监控脚本process_monitor.sh使用方法
- Unity3D之编辑器脚本获取资源内存和硬盘大小
- VisualVM远程监控配置+Tomcat apr 安装+Tomcat 启动脚本
- 资源监控
- 监控脚本
- 监控脚本
- Redhat linux 系统的负载与CPU、内存、硬盘、用户数监控shell脚本
- Redhat linux 系统的负载与CPU、内存、硬盘、用户数监控shell脚本
- 【转载】linux系统的负载与CPU、内存、硬盘、用户数监控shell脚本
- shell脚本: linux系统的负载与CPU、内存、硬盘、用户数监控
- (转)java判断string变量是否是数字的六种方法小结
- 第十一周--项目2用二叉树求解代数表达式
- 如何高效检查一个数组中是否包含某个值
- Linux性能评测工具之一:gprof篇
- android 9path教程与去黑边
- 远程硬盘资源监控通用脚本
- 华为OJ题目(五):字符串最后一个单词的长度
- result cannot be resolved or is not a field
- 关于如何通过域名直接访问程序的项目
- Mysql配置及基础
- yii中UserController cannot find the requested view "goodbye".
- sql2005查询字段名和说明
- C#调用C++dll,C++中char*与C#类型的对应关系
- 欢迎使用CSDN-markdown编辑器