如何添加sersync进程监控脚本
来源:互联网 发布:java字符串反转api 编辑:程序博客网 时间:2024/06/06 02:27
环境介绍
sersync安装在/root/下
发送报警的邮件正文在/etc/sersync/bady.txt
sersync 的日志位置放置在 /etc/sersync/checksersync.log中
脚本会自动将最新的日志内容添加在邮件正文中
以上路径有操作者自己建立
脚本内容如下
#!/bin/bash
# usage:
# 1.将脚本命名为checkrsync.sh 放到/root/
# 2 chmod +x checkrsync.sh 给脚本赋予可执行权限
# 2.添加到计划任务
# */1 * * * * /root/checkrsync.sh
logfile='/etc/sersync/checksersync.log';
function sersync_is_running(){
threadnum=`ps aux|grep sersync2|grep -v grep -wc`; #此处为监控sersync的监控手段,查找sersync2进程
if [ "$threadnum" -eq '0' ];then
echo '0';
else
echo '1';
fi
return;
}
function current_time(){
if [ -z "$1" ];then
format="%Y-%m-%d %H:%M:%S%Z";
else
format=$1;
fi
echo `date +"$format"`;
return;
}
function logtofile(){
echo $(current_time) $2>>$1;
}
function sersync_restart(){
/etc/sersync/sersync2 -r -d -o /etc/sersync/confxml.xml >/dev/null 2>&1;
sleep 3;
threadnum=$(sersync_is_running);
if [ $threadnum -eq '0' ]; then
echo "0";
else
echo '1';
fi
return;
}
isrunning=$(sersync_is_running);
mailzt=`cat $logfile|tail -1 > /etc/sersync/body.txt`
if [ "$isrunning" -eq '0' ];then
logtofile $logfile "mail sersync service was died.";
mail -s "rsync sersync service was died."xxx@xxx.com < /etc/sersync/body.txt
restart=$(sersync_restart);
if [ $restart -eq '0' ];then
logtofile $logfile "sersync service restart failed.";
mail -s "rsync sersync service was died."xxx@xxx.com < /etc/sersync/body.txt
else
logtofile $logfile "sersync service restart success.";
mail -s "rsync sersync service restart success"xxx@xxx.com < /etc/sersync/body.txt
fi
else
logtofile $logfile "sersync service is running.";
fi
exit 0;
test为安装了sersync的主机
sms@126.com为发送报警的邮箱
为保证能够发送报警邮件别忘了把sendmail的服务打开
service sendmail start
- 如何添加sersync进程监控脚本
- zabbix监控sersync
- 进程监控脚本程序
- 进程监控脚本
- shell脚本监控进程
- Sersync启动脚本
- 一个进程监控脚本程序
- linux shell脚本-监控进程
- 进程内存占用监控脚本
- shell脚本监控监听器进程
- 监控进程的shell脚本
- 简单的进程监控脚本
- 一个进程监控脚本程序 .
- cacti如何进行进程监控
- 一个监控指定进程的脚本
- 用shell脚本监控进程,挂掉后重启
- windows监控并重启某个进程 脚本
- python nagios简单监控进程数脚本
- _VARIANT_T 到 CSTRING 转换
- OK6410之ADC驱动程序 混杂设备
- Unix Regex
- f2py的语法(备查)-使用Intel Visual Fortran Compiler编译器
- 关于android报莫名其妙的问题(一)-引用的R文件错误了
- 如何添加sersync进程监控脚本
- ASCII编码
- 通过Eclipse中的Java Build Path 时报错Could not write file: xx:\xx\.classpath
- 删除分节符的技巧
- How to call API in Java
- 关于javascript操作html
- ubuntu10.04双显示器扩展方式,笔记本外接显示器分辨率低增加没有的分辨率
- 从UML类图生成代码
- android – 多屏幕适配相关