[root@localhost /]# cat /home/monitorntp.sh
#!/bin/bash
# 进程名
proc_name='ntpd -u'
# 日志文件
file_name="/home/logs/ntpd.log"
pid=0
# 计算进程数
proc_num()
{
num=`ps -ef | grep "$proc_name" | grep -v grep | wc -l`
return $num
}
# 进程号
proc_id()
{
pid=`ps -ef | grep "$proc_name" | grep -v grep | awk '{print $2}'`
}
proc_num
number=$?
# 判断进程是否存在
echo $number
if [ $number -eq 0 ]
then
# 重启进程的命令,请相应修改
/etc/init.d/ntpd restart
# 获取新进程号
proc_id
# 将新进程号和重启时间记录
echo ${pid}, `date` >> $file_name
fi
====================
*/1 * * * * /home/monitorntp.sh >/dev/null 2>&1
========= Others:
检测surl脚本
#!/bin/bash
count=`ps -ef|grep "surl"|grep -v "grep"|wc -l`
time=$(date +"%Y-%m-%d-%H-%M")
echo $count
if [ $count -lt 1 ]; then
echo "surl ERROR: is down at "$time", process num is "$count
cd /home/dsp/shorturl/
/home/dsp/shorturl/surl &
else
echo "surl ok!"
fi
转载于:https://blog.51cto.com/12223582/1873872