linux 根据进程名来检查程序是否运行 当未运行时自动运行

#!/bin/sh
procedure="registered_rest_server.py"
startup="/home/semantic_analyzer/start.sh"
path="/home/semantic_analyzer"
logfile="/var/log/registered.log"
while :
do
stillRunning=$(ps -ef |grep "/root/anaconda3/bin/python3"|grep "$procedure" |grep -v "grep")
if [ "$stillRunning" ] ; then
echo "`date "+%F %T"` $procedure 程序运行正常" >>$logfile
#echo "在$date $procedure 程序运行正常" >> $logfile
else
echo "`date "+%F %T"` $procedure 程序没有在运行, 正在启动运行脚本" >>$logfile
cd $path
$startup
fi
sleep 10
done

  

posted @ 2021-02-26 13:39  看见酵母菌  阅读(263)  评论(0编辑  收藏  举报