Rotate wtmpx log

por | 14 Abril, 2014
If you like this article, please +1 or Recommend via FB with the provided buttons above:


Article ID: 85
by: Reese K.
Posted: 21 Jan, 2013
Last updated: 21 Jan, 2013
Views: 1507

Once wtmpx hits 2 GB in size, certain unfavorable conditions may occur.  To alleiviate this from happening, I setup a logadm to rotate the log once every two weeks:

~# logadm /var/adm/wtmpx -C 2 -c -p 2w

  • -C number of copies to keep
  • -p time between each log cycle (2 weeks)
  • -c copy and them truncate (doesn’t need to restart a service then)
  • -w writes an entry into /etc/logadm.conf for this log file

The command writes the following to /etc/logadm.conf

logadm -C 2 -s 10m -c -z 0 -w /var/adm/wtmpx

The example below creates an entry in /etc/logadm.conf to manage the log /opt/bb/bbc/BBOUT. It tells logadm to keep four copies (-C 4) of the log file, BBOUT, naming them BBOUT.0, BBOUT.1, etc. as they are rotated. It also tells logadm to rotate the log file when it reaches 5 MB (-s 5m), to rotate the log file by copying it and truncating the original log file to zero length (-c), to compress old log files as they are created keeping none of the most recent log uncompressed (-z 0), and to write an entry in /etc/logadm.conf that corresponds to the current command line arguments (-w /opt/bb/bbc/BBOUT).

# logadm -C 4 -s 5m -c -z 0 -w /opt/bb/bbc/BBOUT
# tail -1 /etc/logadm.conf
/opt/bb/bbc/BBOUT -C 4 -c -s 5m -z 0

Otherwise, you can go through a series of commands to backup the file manually and overwrite it with a clean one.  This was likely the sequence used pre Solaris 9 days when logadm came into the picture.

~# cd /var/adm/
~# /usr/lib/acct/fwtmp < wtmpx > wtmpx.a
~# cp wtmpx.a wtmpx.a.bak
~# cat /dev/null > wtmpx.a
~# /usr/lib/acct/fwtmp -ic < wtmpx.a > wtmpx