加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

linux下自动检测进程并重启

(2010-09-28 17:36:28)
标签:

杂谈

分类: 技术

TEMPLATE_HOME=/home/jxbt/bgprogram
while true
do
        #将programid.txt的内容赋值给变量XL
        x1=(`cat programid.txt`)
        #以逗号分隔符,将内容转成数组
        ids=`echo $x1 | awk -F',' '{print $0}' | sed "s/,/   /g"`
        index=0
        for id in $ids
        do
                ##第一位是此监控脚本的运行标志,1表示运行,0表示停止
                if test $index = 0
                then
                        if test $id = 0
                        then
                                exit
                        fi
                else
                        #每天凌晨0,6,12,18时0分重起程序
                        timenow=(`date +%H%M%S`)
                        timenow=${timenow:0:5}
                        if test $timenow = '00003'
                        then
                                echo "$id终止运行,准备重起......."
                                kill -9 `ps -ef|grep $id|awk '{print $2}'`
                        fi
                        if test $timenow = '06003'
                        then
                                echo "$id终止运行,准备重起......."
                                kill -9 `ps -ef|grep $id|awk '{print $2}'`
                        fi
                        if test $timenow = '11503'
                        then
                                echo "$id终止运行,准备重起......."
                                kill -9 `ps -ef|grep $id|awk '{print $2}'`
                        fi
                        if test $timenow = '17503'
                        then
                                echo "$id终止运行,准备重起......."
                                kill -9 `ps -ef|grep $id|awk '{print $2}'`
                        fi
                        ##统计系统中包含指定名称的进程总数,如果=1表示目标进程没有启动(因为grep -c xxx也统计在内),需要重启
                        num=(`ps ax|grep -c $id`)
                        if test $num != 2
                        then
                                echo $num
                                echo "$id程序异常,重启........."
                                #删除所有僵死进程
                                kill -9 `ps -ef|grep $id|awk '{print $2}'`
                                $TEMPLATE_HOME/bin/$id.sh
                        fi
                fi
                index=$(expr $index + 1)
        done
        sleep 10
done
==========programid.txt内容===========================================

1,SmsServer,MmsServer,ScheduleTaskServer

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有