你好大方的电脑!Shell脚本变量错误?
所以我有一个launchd plist项目,每隔30秒调用一次下面的shell脚本。它检查程序是否正在运行,如果没有,它会重新启动它。或者至少这是它应该做的。
问题是,即使进程已被终止,shell脚本仍在声明进程仍在运行。我认为这是因为布尔值不被重置(或者沿着这些线)。任何帮助?
n=`ps -ef | grep Intel | grep -v grep | wc -l`
if [ $n -gt 0 ]
then
echo `date` CURRENTLY RUNNING. >> /Library/A_Intel_WATCHDOG/A_Intel_WatchLog.txt
else
echo `date` not running. ATTEMPTING RESTART... >> /Library/A_Intel_WATCHDOG/A_Intel_WatchLog.txt
cd /Library/LaunchAgents/
launchctl load com.Intel.plist
fi
编辑1
有人建议,增加了“保活”的说法可能是一个很好的解决方案,以我的一般问题。任何意见?
这里将是我更新的plist文件应当保证我的应用程序一直运行永远:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.Intel</string>
<key>OnDemand</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/Library/LaunchAgents/Contents/Intel</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
我很想听到的话,人们认为这是正确与否。非常感谢!
'ps -ef | grep Intel | grep -v grep | wc -l'或'ps -ef | grep Intel | grep -v grep | wc -l'输出?问题可能是这个过程在某种程度上仍然存在。 – aularon 2010-09-06 19:20:00
检查英特尔进程是否正在运行:) – 2010-09-06 19:21:20
对不起,我不小心发送了,现在检查:) – aularon 2010-09-06 19:21:56