我写了一些bash脚本来完成一些备份工作。我用errexit和pipefail运行脚本,所以我不会错过任何错误。我现在想要的是脚本向我发送一封电子邮件,以防发生错误。我得到了这个工作。但我希望将脚本错误包含在电子邮件正文中。我怎样才能做到这一点?bash通过邮件发送错误
这里是脚本:
#!/bin/bash
# exit script if an error occures
set -o errexit
# even exit if an error in passed through a pipe
set -o pipefail
trap 'ERRORMESSAGE_HERE | mailx -s "Something went wrong on srv-002" [email protected]' ERR
# the backup job here
# if script reaches this point everything went perfectly good
echo "all good!"
非常感谢您的帮助!
http://stackoverflow.com/questions/6784295/capturing-and-mailing-bash-script-errors - 这似乎是一个相关的问题,采取了看看答案是否适合你。 – Yuriy