2

Has anyone written a self-watchdog script and can share the way it was resolved? I have DD-WRT on one of the routers and can make only one startup script. The problem is doesn't get run. If I log on by telnet and start it manually it works great. So I need to add a cron rule to run it, but not run more then once. I was thinking about using:

if [`ps | grep [c]ustom.sh` -gt 1]; then
    exit;
else
    ...
fi

Do you know any other way to do this?

Alakdae
  • 1,213
  • 8
  • 21
  • you could use `pgrep` instead of `ps | grep`. Another option would be to use filesystem locks if there is a theoretical possibility of someone else running a command that contains `custom.sh` in its command line or to deal with hanging scripts. – Dmitri Chubarov Apr 23 '12 at 03:02

1 Answers1

5

You can use a lock that remains in memory (usually /tmp is a tmpfs mount) that will be removed at boot:

[ ! -f /tmp/rc.local.lock ]&&touch /tmp/rc.local.lock||exit

I think that the problem is that you do not have the same environment available in your script compared to ssh shell (e.g. PATH...). You should write the output of the script in a log file. Just add this line at the beginning of the script.

exec >/tmp/rc.local.log 2>&1
Mircea Vutcovici
  • 16,706
  • 4
  • 52
  • 80