目的:每隔*分钟检测服务是否运行;若运行中,则记录执行的进程名称;若不运行,记录当前时间
shell:
#!/bin/bash
date=`date +%Y%m%d`
log=/home/mono_${date}.log
err_log=/home/ERR_${date}.log
if [ ! -f ${log} ]; then
touch ${log}
fi
if [ ! -f ${err_log} ]; then
touch ${err_log}
fi
PATH=PATH:/sbin:/bin:/usr/bin
cmd=`ps -ef | grep mono | grep -v grep | wc -l`
if [ ${cmd} -eq 1 ]; then
date >> ${err_log}
else
date >> ${log}
ps -ef | grep mono >> ${log}
echo "*************************" >> ${log}
fi
crontab -e
*/5 * * * * /bin/sh /home/mono_stat.sh