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.

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
add comment

1 Answer 1

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
add comment

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.