Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
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 3:02

1 Answer 1

up vote 5 down vote accepted

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
share|improve this answer
    
Thanks a lot! The script output dump helped A LOT in debugging! –  Alakdae Apr 23 '12 at 3:36
    
I am so glad it helped. –  Mircea Vutcovici Apr 23 '12 at 4:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.