我正在编写一个 bash 脚本,当各种系统资源的使用量超出某个阈值时,它会通过电子邮件发送警报。
我已经设置了脚本,使电子邮件正文的第一行“发件人:ALERTS[电子邮件保护]“(并且我已确保服务器的 Linux 主机名是 mydomain.com)
但邮件传递失败,并且 Postfix 日志似乎表明电子邮件正在发送[电子邮件保护]作为发件人地址,我怀疑这就是阻止投递的原因。
fwiw 当我使用电子邮件客户端时,从/向这些帐户/域发送电子邮件工作正常,只有从 Linux 服务器发送时邮件传递才会失败。
这是 bash 脚本:
NL=$'\n'
DNL=$'\n\n'
# compose email for admin notification
EM_BODY="From: ALERT <[email protected]>${NL}"
EM_BODY+="Subject: WARN: sustained high CPU load${DNL}"
# add general description of alert
EM_BODY+="WARNING: CPU load on linux server higher than 90% for more than 15 second
# add snapshot of CPU usage
EM_BODY+="$(ps -eo user,tty,pid,cmd:80,%cpu --sort=-%cpu | head -n 15)${DNL}"
# specify recipient address
MAILTO="[email protected]"
# send email
echo "$EM_BODY" | /usr/sbin/sendmail -t $MAILTO
...这是 Postfix 日志输出(替换了域名):
Aug 1 14:48:47 mydomain postfix/error[229579]: 34597FCD50: to=<[email protected]>, relay=none, delay=64951, delays=64951/0.11/0/0, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to eforward5.registrar-servers.com[162.255.118.51]:25: Connection timed out)
Aug 1 14:48:47 mydomain postfix/error[229571]: 8476CFCC48: to=<[email protected]>, relay=none, delay=98671, delays=98670/0.11/0/0.01, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to eforward5.registrar-servers.com[162.255.118.51]:25: Connection timed out)
Aug 1 14:48:47 mydomain postfix/error[229583]: 6A19DFCCF9: to=<[email protected]>, relay=none, delay=77431, delays=77431/0.11/0/0.01, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to eforward5.registrar-servers.com[162.255.118.51]:25: Connection timed out)
Aug 1 14:48:47 mydomain postfix/error[229575]: 95128FCD40: to=<[email protected]>, relay=none, delay=69150, delays=69150/0.11/0/0.01, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to eforward5.registrar-servers.com[162.255.118.51]:25: Connection timed out)
Aug 1 14:50:17 mydomain postfix/pickup[228607]: 055FBFCDB6: uid=0 from=<root>
Aug 1 14:50:17 mydomain postfix/cleanup[229640]: 055FBFCDB6: message-id=<[email protected]>
Aug 1 14:50:17 mydomain postfix/qmgr[156914]: 055FBFCDB6: from=<[email protected]>, size=363, nrcpt=1 (queue active)
Aug 1 14:50:17 mydomain postfix/error[229570]: 055FBFCDB6: to=<[email protected]>, relay=none, delay=0.03, delays=0.02/0/0/0.01, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to eforward5.registrar-servers.com[162.255.118.51]:25: Connection timed out)
Aug 1 14:50:23 mydomain postfix/pickup[228607]: 67708FCDB7: uid=0 from=<root>
Aug 1 14:50:23 mydomain postfix/cleanup[229640]: 67708FCDB7: message-id=<[email protected]>
Aug 1 14:50:23 mydomain postfix/qmgr[156914]: 67708FCDB7: from=<[email protected]>, size=2071, nrcpt=1 (queue active)
Aug 1 14:50:23 mydomain postfix/error[229573]: 67708FCDB7: to=<[email protected]>, relay=none, delay=0.01, delays=0.01/0/0/0, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to eforward5.registrar-servers.com[162.255.118.51]:25: Connection timed out)
Aug 1 14:52:16 mydomain postfix/pickup[228607]: 9FD06FCDB8: uid=0 from=<root>
Aug 1 14:52:16 mydomain postfix/cleanup[229720]: 9FD06FCDB8: message-id=<[email protected]>
Aug 1 14:52:16 mydomain postfix/qmgr[156914]: 9FD06FCDB8: from=<[email protected]>, size=363, nrcpt=1 (queue active)
任何见解都将不胜感激!