There are some missprints. Try something like this
#!/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
Note that in the shebang (first line) you should not put a space between #!
and the path of the shell, with the test operator []
you need to put spaces inside the brackets: for example this is [ OK ]
this in [NOT OK]
.
If I properly understand your purpose you want to restart only if there are less than 2 occurrences, so inside the IF statement.
Update:
#!/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