Pergunta

I've been trying to kill a process with a batch script and I can't seem to get it working I've read a lot of tutorials online and tried different things and I can't seem to get it to kill the process

how it's run: (crontab)

* * * * * /home/pi/status.sh > /home/pi/logs/status.log 2>&1

log:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
  Dload  Upload   Total   Spent    Left  Speed
^M  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0^M100    10  100    10    0     0     73      0 --:--:-- --:--:-- --:--:--   153^M100    10  100    10    0     0     72      0 --:--:-- --:--:-- --:--:--   $
/home/pi/status.sh: 6: /home/pi/status.sh: 18645: not found

status.sh:

Bridge=$(curl http://www.mywebsite.com/dir/cache/timestamp.txt)
timestamp=$( date +%s )

total=`expr $timestamp - $Bridge`

if (($total > 300));
then
#p=$(pidof cgminerEU)
#sudo killall -9 cgminerEU
#sudo kill -9 $(pidof cgminerEU)
sudo pkill -f cgminerEU
fi

the process in question

pi@raspberrypi ~ $ ps ax | grep cgminerEU
26018 ?        Ss     0:13 SCREEN -dm ./cgminerEU
26019 pts/0    Ssl+  89:32 ./cgminerEU
30989 pts/2    S+     0:00 grep --color=auto cgminerEU

does the /home/pi/status.sh: 6: /home/pi/status.sh: 18645: not found mean that it's trying to kill pid 18645? I'm sorry I'm new to bash scripting and it's all very confusing

Foi útil?

Solução

I suspect you'll find that this is due to a race condition.

  1. If you kill screen, cgminerEU will immediately die and vice versa
  2. You've made pkill send a signal to both processes

pkill is in a race to kill the second process before it dies.

I suggest you try removing the -f from pkill to make it kill only by process name and not full command line.

This way, it will kill only the cgminerEU process and not the screen process of the same name (which will die as a dependency anyways).

PS: curl has a -s to avoid getting emailing the progress indicator.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top