这里有一个很好的答案: https: //unix.stackexchange.com/questions/314640/how-to-make-cron-send-email-with-error-log-when-script-throws-errors
简而言之,它说:
20 6-10 * * 1-5 ~/job_failure_test.sh > ~/job_fail.log 2>&1 || mail -s "Errors" myemail@something.com < ~/job_fail.log
Run Code Online (Sandbox Code Playgroud)
但请点击问题的链接,因为那里有一些很好的指示。