首页 > 编程语言 > 详细

使用Shell或其他脚本语言编写一个针对Linux进程监控及故障重启的脚本

时间:2019-06-30 10:05:53      阅读:101      评论:0      收藏:0      [点我收藏+]

1.shell通过一个while-do循环,用ps -ef|grep检查loader进程是否正在运行,如果没有运行,则启动,

这样就保证崩溃挂掉的进程重新被及时启动。

注意2点:1.ps -ef |grep 一个进程时必须加上其路径,否则容易grep到错误的结果;

             2.必须用-v 从结果中去除grep命令自身,否则结果非空。

#!/bin/sh ?
while
?do 
?echo "Current DIR is " $PWD ?
stillRunning=$(ps -ef |grep "$PWD/loader" |grep -v "grep") ?

if [ "$stillRunning" ] ; then 
?echo "TWS service was already started by another way" ?

echo "Kill it and then startup by this shell, other wise this shell will loop out this message annoyingly" ?

kill -9 $pidof $PWD/loader 
?else ?

echo "TWS service was not started" ?

echo "Starting service ..." ?$PWD/loader ?

echo "TWS service was exited!" ?

fi ?sleep 10 ?

done 

    如果启动此shell时发现进程以及存在,说明已别的方式启动了进程,那么他会持续提醒找到进程,

解决办法是,只要一经发现是其他方式启动此进程即kill掉(kill -9 $PWD/loader)

 

使用Shell或其他脚本语言编写一个针对Linux进程监控及故障重启的脚本

原文:https://www.cnblogs.com/arvin-feng/p/11108750.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!