Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
General
cancel
Showing results for 
Search instead for 
Did you mean: 

Automatically "recreate" mail.log on reboot ?

SOLVED
Go to solution
Stuart Abramson_2
Honored Contributor

Automatically "recreate" mail.log on reboot ?

You know how a reboot moves /var/adm/syslog/syslog.log to "OLDsyslog.log" and creates a new "syslog.log"?

Can I set something up to do the same thing for "mail.log"?: move mail.log to OLDmail.log and create a new mail.log?

Is there some flag to do that?

Our "mail.log" files get so big that they become a problem. We don't trim them in cronjobs - what do you do?
12 REPLIES
Stuart Abramson_2
Honored Contributor

Re: Automatically "recreate" mail.log on reboot ?

Please don't tell me how to clean up the mail.log. I know how to do that. I just want to know if I can set it up at reboot time, or should I do it in a cronjob...
Michael Schulte zur Sur
Honored Contributor
Solution

Re: Automatically "recreate" mail.log on reboot ?

Hi,

you find the procedure in:
/sbin/init.d/syslogd
You probably could do it, when the sendmail daemon is started.

Michael
Jean-Luc Oudart
Honored Contributor

Re: Automatically "recreate" mail.log on reboot ?

The 1st solution implies it only happens when you reboot your server and therefore may not answer your mail.log size pb.

You may have to use cron
you can copy the file to different location (and gzip it)then reset with

> mail.log

Regards,
Jean-Luc
fiat lux
Jeff Schussele
Honored Contributor

Re: Automatically "recreate" mail.log on reboot ?

Hi,

You'll have to add code to the /sbin/init.d/sendmail script - like


mv /var/adm/syslog/mail.log /var/adm/syslog/OLDmail.log

This is the way syslog startup does it.
NOTE: these scripts are fair game for overwrite on patch installs or upgrades.
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Sridhar Bhaskarla
Honored Contributor

Re: Automatically "recreate" mail.log on reboot ?

Hi,

There isn't any script that will move mail.log file through startup. You can configure one that will do it for you. Make sure that script starts before syslogd script though by putting the links with lower number than syslogd in sbin/rc2.d directory.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Jeff Schussele
Honored Contributor

Re: Automatically "recreate" mail.log on reboot ?

Oops forgot to add you'll have to touch mail.log after the mv or as syslogd does it
> /var/adm/syslog/mail.log

Later,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Michael Schulte zur Sur
Honored Contributor

Re: Automatically "recreate" mail.log on reboot ?

Hi,

you will want to stop syslogd and then you can mv mail.log like syslog.log.

Michael
Stuart Abramson_2
Honored Contributor

Re: Automatically "recreate" mail.log on reboot ?

It looks like the best place to put it is inside the "/sbin/init.d/syslogd" script, right after:

if [ -f /var/adm/syslog/syslog.log ]; then
mv /var/adm/syslog/syslog.log /var/adm/syslog/OLDsyslog.
log
mask=`umask`
umask 022
> /var/adm/syslog/syslog.log
umask $mask
fi

But, as someone pointed out above, we reboot some servers every other weekend, but some servers we NEVER reboot. So, I'll probably do a cronjob.

Thanks for your help...
Sridhar Bhaskarla
Honored Contributor

Re: Automatically "recreate" mail.log on reboot ?

To clarify a bit more sendmail and syslogd (may not be bad) scripts isn't an excellent place to put the code in due to

1. It could be overwritten. swinstalls won't overwrite /sbin/init.d/ files. But you may yourself replace it with a new version later.
2. syslogd that holds locks on this file starts before sendmail.

So, it's better to write a seperate script that starts before syslogd in my 2 cents opinion.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Steven E. Protter
Exalted Contributor

Re: Automatically "recreate" mail.log on reboot ?

here is how i do it in the /sbin/init.d/sendmail startup script

/usr/bin/mv /var/adm/syslog/mail.log /tmp
/usr/bin/touch /var/adm/syslog/mail.log
/usr/bin/chmod 000 /var/adm/syslog/mail.log
/usr/bin/chmod a+r /var/adm/syslog/mail.log

I don't have access to the box, so this is a paraphrase.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Jeff Schussele
Honored Contributor

Re: Automatically "recreate" mail.log on reboot ?

Sri makes a good point - as always....
syslogd start *before* (220 vs 540) than sendmail.
So it's probably gotta be a diff startup OR or sendmail bounce to make sure.

Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Geoff Wild
Honored Contributor

Re: Automatically "recreate" mail.log on reboot ?

Another alternative is to use something like logrotate:

Logrotate is designed to ease administration of systems that generate large numbers of log files. It allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or when it grows too large.

http://hpux.ee.ualberta.ca/hppd/hpux/Sysadmin/logrotate-2.5/

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.