acct cronjob does not work if using dateext in logrotate
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/
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=
EXTENSION=`echo "$LASTLOG" | cut -d'.' -f2`
if [ "$EXTENSION" == "gz" ]
then
WTMP=
trap "rm -f -- '$WTMP'" EXIT
gunzip -c $LASTLOG > "${WTMP}"
else
WTMP=$LASTLOG
fi
summary: |
- acct cronjob does not work if using dateext logrotation + acct cronjob does not work if using dateext in logrotate |
description: | updated |