[Bug 1842512] [NEW] acct cronjob does not work if using dateext in logrotate

M 1842512 at bugs.launchpad.net
Tue Sep 3 20:34:00 UTC 2019


Public bug reported:

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

** Affects: acct (Ubuntu)
     Importance: Undecided
         Status: New

** Summary changed:

- acct cronjob does not work if using dateext logrotation
+ acct cronjob does not work if using dateext in logrotate

** Description changed:

- When you switch to dateext logrotate format the /etc/cron.monthly/acct
- script assumes logrotate will create a file named .1 or .1.gz
+ 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.  Check the file
- extension, and use trap to remove the tempfile at the end of execution.
+ /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}"
+     WTMP=$(tempfile)
+     trap "rm -f -- '$WTMP'" EXIT
+     gunzip -c $LASTLOG > "${WTMP}"
  else
-     WTMP=$LASTLOG
+     WTMP=$LASTLOG
  fi

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to acct in Ubuntu.
https://bugs.launchpad.net/bugs/1842512

Title:
  acct cronjob does not work if using dateext in logrotate

Status in acct package in Ubuntu:
  New

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

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/acct/+bug/1842512/+subscriptions



More information about the foundations-bugs mailing list