定时检查进程的shell脚本

来源:互联网 发布:js判断数组是否为空 编辑:程序博客网 时间:2024/05/22 14:43
#!/bin/bash
#TIME=18:32
#while [ 1 -eq 1 ]
#do
#TMP=`date +'%H:%M'`
#echo $TMP $TIME
#if [ "$TMP" = "$TIME" ]
#then
#echo "时间到了,开始执行程序"
#break
#fi
#sleep 1
#done
lryDir=/settle1/card2/script/lry
echo "每隔5分钟检查一次进程"
lrynow=`date +%Y%m%d`
if [ -f $lryDir/Log/log_check_$lrynow ]
then
echo "文件已经存在,采用追加方式"
>> $lryDir/Log/log_check_$lrynow
echo "`date +%T` :文件已经存在,采用追加方式" | tee -a $lryDir/Log/log_check_$lrynow
else
> $lryDir/Log/log_check_$lrynow
echo "`date +%T` :新建日志文件log_check_$lrynow" | tee -a $lryDir/Log/log_check_$lrynow
fi
echo "每隔5分钟检查一次进程" |tee -a $lryDir/Log/log_check_$lrynow
TIME=0900
checkcard_ps()
{
checkps=$1
if [ $checkps = Standserver ]
then
echo "`date +%T` : 当前进程为:$checkps"
fi
status=`pscard | grep $checkps | wc -l`
#echo $status
if [ $status == 0 ]
then
echo "`date +%T`的时候:$checkps进程挂掉了,准备运行$checkps" | tee -a $lryDir/Log/log_check_$lrynow
cd /settle1/card2/bin
nohup $checkps &
echo $?
if [ $? -eq 0 ]
then
echo "`date +%T`时候:程序$checkps启动成功" | tee -a $lryDir/Log/log_check_$lrynow
sleep 60
if [ $checkps = Standserver ]
then
echo "!!!!!!`date +%T`时候:准备修改配置文件" | tee -a $lryDir/Log/log_check_$lrynow
cat /settle1/card2/script/lry/lryconfig > /settle1/card2/bin/config.ini
echo "!!!!!!`date +%T`时候:配置文件修改完毕" | tee -a $lryDir/Log/log_check_$lrynow
fi
fi
sleep 5
else
echo "`date +%T` : $checkps正常运行"
sleep 1
fi
}
echo "`date +%T` : $lrynow开始执行检查进程程序" | tee -a $lryDir/Log/log_check_$lrynow
while [ 1 -eq 1 ]
do
TMP=`date +'%H%M'`
for lryps in SettleAgent Standserver Cardcollect Statserver Import Billserver osagent Msgserver
do
echo "$lryps"
checkcard_ps $lryps
done
echo "`date +%T` : 检查完毕"
echo $TMP
echo $TIME
if [ "$TMP" -gt "$TIME" ]
then
echo "`date +%T` : 时间到了,退出程序" | tee -a $lryDir/Log/log_check_$lrynow
break
fi
sleep 291
done