简体   繁体   English

关闭/重新启动期间无法发送Unix邮件

[英]Unable to send unix mail during shutdown/reboot

We have a perl script which tries to send an email notification when the system is about to shut down. 我们有一个perl脚本,它会在系统即将关闭时尝试发送电子邮件通知。 To do this, we catch the SIGTERM and call Unix mail command to send email in the signal handler. 为此,我们捕获SIGTERM并调用Unix mail命令以在信号处理程序中发送电子邮件。 SIGTERM is caught but the unix mail log shows that the FROM and TO address are changed from user@companyname.com to user@hostname during shutdown. 捕获了SIGTERM,但是Unix邮件日志显示在关闭期间,FROM和TO地址已从user@companyname.com更改为user @ hostname。 Any idea why the system does this and how to prevent it? 知道为什么系统会这样做以及如何预防吗? (Please note: The same email works fine when we run the script and kill the process from terminal) (请注意:当我们运行脚本并从终端终止进程时,同一封电子邮件也可以正常工作)

Here is the perl code snippet: 这是perl代码段:

$SIG{TERM} = \&signal_handler;

sleep(3600);

sub signal_handler { 

my $email_address = 'user@companyname.com';

system("echo \"TestBody\" | mail -s \"TestEmailSubject\" -c \"$email_address\" -r \"$email_address\" \"$email_address\"");

}

Here is what is printed in /var/log/mail/mail during shutdown: 这是关机期间在/ var / log / mail / mail中打印的内容:

Sep 17 21:17:04 postfix/postfix-script[7009]: starting the Postfix mail system

Sep 17 21:17:10 postfix/master[7011]: daemon started -- version 2.10.1, configuration /etc/postfix

Sep 17 21:17:10 postfix/pickup[10349]: 35F801809C9: uid=0 from=root

Sep 17 21:17:10 postfix/cleanup[10356]: 35F801809C9: message-id=<20190917211710.35F801809C9@HOSTNAME.net>

Sep 17 21:17:10 postfix/qmgr[10350]: 35F801809C9: from=root@HOSTNAME.net, size=1618, nrcpt=1 (queue active)

Sep 17 21:17:10 postfix/local[10372]: 35F801809C9: to=root@HOSTNAME.net, orig_to=<root>, relay=local, delay=13, delays=13/0.01/0/0, dsn=2.0.0, status=sent (delivered to file: /dev/null)

Here is the working case when we kill the process from terminal: 这是当我们从终端终止进程时的工作情况:

Sep 17 21:20:41 postfix/pickup[10349]: E5328180968: uid=14936 from=user@COMPANYNAME.com

Sep 17 21:20:41 postfix/cleanup[22690]: E5328180968: message-id=<5d814e29.qZd+wgg47afpUdbd%user@COMPANYNAME.com>

Sep 17 21:20:41 postfix/qmgr[10350]: E5328180968: from=user@COMPANYNAME.com, size=544, nrcpt=1 (queue active)

Sep 17 21:20:41 postfix/smtp[22692]: E5328180968: to=user@COMPANYNAME.com, delay=0.06, delays=0.01/0/0/0.05, dsn=2.0.0, status=sent (250 2.0.0 OK 4E/77-59832-92E418D5)

the postfix system is probably being shut down earlier in the shutdown process than your script. postfix系统可能在关闭过程中比脚本更早地关闭。 Have you confirmed within your script that the mail system is still up after your script has tried to send an email? 您是否已在脚本中确认脚本尝试发送电子邮件邮件系统仍处于启动状态?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM