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

  

原文地址:https://www.cnblogs.com/kjjmj/p/14451877.html