System Administration Guide
Chapter 2, Administering filesystems

Clearing log files automatically

Clearing log files automatically

You can clear log files automatically using crontab(C) and cron(C). By adding a line to root's crontab file (/usr/spool/cron/crontabs/root), you can make your own file maintenance scripts execute daily, weekly, or monthly.

The following is one of the default entries in root's crontab file:

   17 5 * * 0 /etc/cleanup > /dev/null
See crontab(C) manual page for complete information on the format of the crontab file.

This entry runs /etc/cleanup each Sunday morning at 5:17.

NOTE: If multiple machines mount the same NFS filesystems, all machines will run the find at the same time, searching all the NFS-mounted filesystems as well as the local filesystems. Therefore, running this script without some modifications could impose heavy network load. For example, adding the -mount or -local options to the find(C) command will restrict the search to the root filesystem, or local filesystems, respectively.

The /etc/cleanup script looks like this: 

# clean up super-user log
cp /usr/adm/sulog /usr/adm/Osulog
> /usr/adm/sulog
# clean up volcopy log
[ -f /etc/log/filesave.log ] && mv /etc/log/filesave.log /etc/log/Ofilesave.log
> /etc/log/filesave.log
chown root /etc/log/filesave.log
chgrp sys /etc/log/filesave.log
chmod 666 /etc/log/filesave.log
# clean up wtmp
> /etc/wtmp
# clean up miscellaneous files
find / -name core -atime +7 -exec rm -f {} \;
The /etc/cleanup script:

You can specify different files to clear and when to clear them by modifying /etc/cleanup and the /usr/spool/cron/crontabs/root file.