Linux系统监测python程序挂掉并重启

来源:互联网 发布:java stack overflow 编辑:程序博客网 时间:2024/06/03 15:18

1、shell脚本,fi后输入Enter键,不然会出错误,若在windows下编写shell脚本,上传到Linux后,vi 文件名,输入 :set ff?, 若为dos,则需要修改为Linux格式,:set ff=unix 然后输入:wq!保存退出。

#!/bin/shcount=`ps -ef |grep /usr/local/jobmail/Study/TomasSendNew2.py |grep -v "grep" |wc -l`echo $countif [ 0 == $count ];thennohup python2.7 /usr/local/jobmail/Study/TomasSendNew2.py > /usr/local/jobmail/Study/TomasSendNew2.log 2>&1 &echo $countfi

若TomasSendNew2.py正常运行,则count=1,若挂掉,则count=0,这时就需要重启。
2、crontab 定时运行shell脚本
定时触发.sh
crontab -e 写入0 */3 * * * /usr/local/jobmail/Study/restartSend.sh,代表每隔三分钟运行.sh
crontab -l 可查看crontab文件。

原创粉丝点击