#! /bin/sh
#
# cron script to perform monthly login accounting.
#
# Written by Ian A. Murdock <imurdock@gnu.ai.mit.edu>
# Modified by Dirk Eddelbuettel <edd@debian.org>   

LOGROTATE=/etc/cron.daily/logrotate

if [ -x /usr/sbin/accton ]
then
    echo "Login accounting for the month ended `date`:" > /var/log/wtmp.report
    echo >> /var/log/wtmp.report

    # The logrotate script happens to run before this one, effectively swallowing 
    # all information out of wtmp before we can use it. Hence, we need to use the
    # previous file. Bad clutch.
    # Too bad we never heard from the logrotate maintainer about this ...
    if [ -f $LOGROTATE ] && [ -x /usr/sbin/logrotate ]
    then
	ac -f /var/log/wtmp.1 -p | sort -nr +1 >> /var/log/wtmp.report
	echo >> /var/log/wtmp.report
	last -f /var/log/wtmp.1 >> /var/log/wtmp.report
    else
	ac -p | sort -nr +1 >> /var/log/wtmp.report
	echo >> /var/log/wtmp.report
	last >> /var/log/wtmp.report
    fi

fi
