I’ve a few cronjobs that run small PHP scripts every 1 or 2 minutes. Obviously I don’t want e-mail every minute. I do want to know when the cron failed or when it encountered any kind of error (= notice, warning, error or uncaught exception).
My PHP scripts print a lot of meta data (using echo) so it can be run manually and inspected. I want all of that meta data to be sent to me IF an error occurred. If no error occurred, I don’t want mail, but because there’s output, cron sends me an e-mail anyway.
Is there a way to have cron ONLY send me the entire output IF an error occurred?
- I don’t want to manually send an e-mail
- I rather not use ob (if that’s even possible inside a cronjob)
- I’m Okay with changing my output method (
printor a custom function instead ofechoetc)
Check out crronic – it’s a shell wrapper that provides this functionality:
http://habilis.net/cronic/
Note that you’ll need to exit with a nonzero exit value in case of an error (in order to trigger the mail).