I need to put into my crontab small command, which is checking, if lighttpd web server is running, for some reason it hangups sometimes. So I got there:

*      *       *       *       *       root    /bin/pgrep lighttpd || /usr/local/etc/rc.d/lighttpd restart >/dev/null 2>&1

problem is, this send me mail every minute, in the mail is number of PID of lighttpd, which is running. For other crontab job, redirection work, so I assume, when is there "||", it makes problem.

maybe there should be better to rewrite crontab job, so it uses exit status of pgrep, so I can avoid "||". I am using FreeBSD.

Thanks for any help, for now I disabled this job

link|improve this question
feedback

1 Answer

Redirect the output of pgrep to /dev/null. All you want is the exit status.

/bin/pgrep lighttpd > /dev/null 2>&1 || /usr/local/etc/rc.d/lighttpd restart >/dev/null 2>&1

link|improve this answer
thanks a lot, this seems it is working, and is quite logical. The problem is, I can test it only using crontab, in command prompt it writes "Ambiguous output redirect." – 2ge Jan 3 '11 at 17:54
@2ge Your interactive shell is probably tcsh. Try running sh first before testing the command. – Mark Wagner Jan 4 '11 at 17:00
feedback

Your Answer

 
or
required, but never shown

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