Logs

如何使 sendmail 寫入新的郵件日誌

  • February 4, 2018

我想輪換我的郵件日誌,但我想確保新輪換的日誌包含上一個日誌的最後 2M 行:

   # write the last 2M lines to a new log
   tail -n 2000000 /var/log/maillog > /var/log/maillog.new

   # move the existing log to datestamped backup
   datestamp=`date "+%Y%m%d"`
   mv /var/log/maillog /var/log/maillog.$datestamp

   # move the new log to normal log
   mv /var/log/maillog.new /var/log/maillog

   # tell sendmail to reload
   killall -HUP sendmail

這一切都有效,除了 sendmail 繼續寫入備份日誌文件“maillog.yyyymmdd”而不是正確的“maillog”!

什麼是正確的方法來做到這一點,而不必先停止 sendmail,輪換,然後重新開始?

通常郵件日誌是由 寫的syslogd,而不是sendmail自己寫的,所以你應該發送 SIGHUP 到syslogd

您可以創建自己的日誌文件

[admin@local ~]# killall sendmail
[admin@local ~]# touch /var/log/sendmail.log
[admin@local ~]# sendmail -bd -q15m >> /var/log/sendmail.log

[admin@local ~]# tail -f /var/log/sendmail.log

451 4.0.0 /fake/path/sendmail.cf: line 0: cannot open: No such file or directory

引用自:https://unix.stackexchange.com/questions/6990