Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

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

share|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

Your Answer


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.