#!/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