acct cronjob does not work if using dateext in logrotate

Bug #1842512 reported by M
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
acct (Ubuntu)
New
Undecided
Unassigned

Bug Description

When you switch to dateext logrotate format you get logfiles of the format /var/log/wtmp-YYYYMMDD or /var/log/wtmp-YYYYMMDD.gz the /etc/cron.monthly/acct script assumes logrotate will create a file named .1 or .1.gz

This isn't necessarily the best solution, but here is one I came up with. Uses find to find all logfiles named wtmp, wtmp-* or wtmp.[0-9]* (this script creates a wtmp.report which would match wtmp.*), and then uses ls and sed to get the 2nd most recent file, or it will default to /var/log/wtmp if there isn't a 2nd most recent file. Checks the file extension, and uses trap to remove the tempfile at the end of execution.

Switched to bash from sh

Excerpt:

LASTLOG=`find /var/log -name "wtmp" -o -name "wtmp.[0-9]*" -o -name "wtmp-*" | xargs ls -1t | sed -n '2p'`
LASTLOG=${LASTLOG:-"/var/log/wtmp"}
EXTENSION=`echo "$LASTLOG" | cut -d'.' -f2`
if [ "$EXTENSION" == "gz" ]
then
    WTMP=$(tempfile)
    trap "rm -f -- '$WTMP'" EXIT
    gunzip -c $LASTLOG > "${WTMP}"
else
    WTMP=$LASTLOG
fi

M (mbest)
summary: - acct cronjob does not work if using dateext logrotation
+ acct cronjob does not work if using dateext in logrotate
description: updated
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.