Reputation: 53821
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?
print
or a custom function instead of echo
etc)Upvotes: 2
Views: 1280
Reputation: 6419
Check out crronic - it's a shell wrapper that provides this functionality:
Note that you'll need to exit with a nonzero exit value in case of an error (in order to trigger the mail).
Upvotes: 2