linux shell 如果程序停止了,则自动重启
while true
do
ps -ef | grep 23335 | grep -v "grep"
if [ "$?" -eq 1 ]
then
./shart.sh
#启动应用,修改成自己的启动应用脚本或命令
echo "process has been restarted!"
else
echo "process already started!"
fi
sleep 10
done
备注:
如果window写的shell在linux会报错:
syntax error: unexpected end of file
解决方法:
这是因为Windows和linux的文件格式不同。
vi demo.sh
:set fileformat=unix
:wq
参考链接:
https://jingyan.baidu.com/article/39810a23a124dfb636fda612.html
https://blog.youkuaiyun.com/km_moon/article/details/84730442