linux 根据进程名来检查程序是否运行 当未运行时自动运行
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #!/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 |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步