答案1
有一些印刷错误。尝试这样做
#!/bin/bash
pgrepN=$( pgrep deluge | wc -l )
if [ "$pgrepN" -lt "2" ]; then
echo "less then 2" # pkill deluge
echo here restart deluge # restart only if there were less than 2
fi
请注意,在 shebang (第一行) 中,您不应在#!
和 shell 的路径之间放置空格,使用测试运算符时,[]
您需要在括号内放置空格:例如,这是[ OK ]
中的这个[NOT OK]
。
如果我正确理解了您的目的,您只想在出现次数少于 2 次时重新启动,因此在 IF 语句内。
更新:
#!/bin/bash
Time_to_Sleep="5m" # Put here the amount of time
DKiller="/tmp/Kill_Deluge_Script.sh" # Put here the deluge killer script Name
echo "#!/bin/bash" > $DKiller # Creating script that will kill this one
echo "kill $$; sleep 3s; " >> $DKiller # Passing the command to kill this one
echo "pkill deluge" >> $DKiller # Now you can kill deluge too
echo "echo deluge killed... RIP " >> $DKiller
chmod u+x $DKiller # Make the script executable for you
while true
do
pgrepN=$( pgrep deluge | wc -l )
if [ "$pgrepN" -lt "2" ]; then
echo "less then 2" # pkill deluge
echo here restart deluge # restart only if there were less than 2
fi
sleep $Time_to_Sleep
done