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?