0

I'd like to restart a program regardless of it already running or not using crontab.

I have this in crontab -e

* * * * * /usr/bin/pkill -f myapp; /home/ubuntu/xyz/bin/res.sh

And in the res.sh

#!/bin/bash

/usr/bin/pkill -f myapp

sleep 10

/home/ubuntu/xyz/bin/myapp & &>/dev/null

The problem is if the program is running, it kills the program. but it fails to start the program again.

I don't want to use any condition as to check if the program is already running and start only if it's not.

EDIT: The program is not a service to use "/etc/init.d/service restart" or "sudo service myapp restart"

Thanks.

Questions
  • 195
  • 1
  • 14
  • 1
    You should redirect output to a log file instead of throwing it away, so you can see what happens. – Benjamin W. Oct 05 '17 at 16:09
  • I already tried to redirect the output but the file is empty, it's same case when using 'nohup' – Questions Oct 05 '17 at 16:23
  • The [cron tag wiki](https://stackoverflow.com/tags/cron/info) has a great debugging instructions. Have you tried all of these? – Benjamin W. Oct 05 '17 at 16:27
  • Don't you think It should be `* * * * * /usr/bin/pkill -f myapp; sh /home/ubuntu/xyz/bin/res.sh` – Arun Pal Oct 05 '17 at 16:34
  • @BenjaminW. I did check that thread but am not sure what I missed. arun pal I tried that option too, no success. – Questions Oct 05 '17 at 16:51
  • For one, the `&` operator is equivalent to a `;` in that it ends a statement, so your command is equivalent to `myapp; &>/dev/null`. Do not put it anywhere but the end of a statement. – Sammitch Oct 05 '17 at 23:04

0 Answers0