Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to rotate my maillog, but I want to make sure the newly rotated log contains the last 2M lines from the previous log:

    # 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

This all works, except for the fact that sendmail continues to write to the backup log file "maillog.yyyymmdd" instead of the proper "maillog"!

What is the correct way to do this without having to stop sendmail first, rotate, then start again?

share|improve this question
up vote 2 down vote accepted

Usually maillog written by syslogd, not by sendmail itself, so you should send SIGHUP to syslogd

share|improve this answer
Thanks - that did it. – jemminger Feb 6 '11 at 20:41

You can create your own log file

[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
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.