How can I get logrotate dateext to reflect the log date rather than the rotation date?

253

Solution 1

Added in 3.8.0 (although looking at the svn history, it looks like it was actually added in 3.7.9):

http://svn.fedorahosted.org/svn/logrotate/tags/r3-8-0/CHANGES

- added "dateyesterday" option (see man page)

Solution 2

if logrotate in your distrib doesn't have 'dateyesterday' option yet, you can use script like the following:

LOGFILE="$1"
LOGMTIME="$(env LC_ALL='C' stat $LOGFILE |awk '/^Modify/{print $2}')"
LOGSTART=$(( $(date +%Y%m%d -d "${LOGMTIME}") - 1 ))
mv $LOGFILE ${LOGFILE%-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]}-$LOGSTART

Notes:

  1. script will work right only in case of 'daily' option
  2. if operating on multiple files, wrap the code block in "for LOGFILE in $@" loop.
  3. sequence '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' is the logrotate's default glob pattern, see description of dateext option of logrotate man.
Share:
253

Related videos on Youtube

compyutech
Author by

compyutech

Updated on September 18, 2022

Comments

  • compyutech
    compyutech over 1 year

    I am working on a application that is using google service account with domain wide delegation.

    I don't want client to do setting of domain wide delegation and download private key. I could create private key using IAM api.

    is there a way to achieve domain wide delegation also via API ?

    Thanks

  • jsonx
    jsonx about 10 years
    Despite the name, dateyesterday works even if you are rolling monthly (with something like dateformat .%Y-%m), and will use last month's number
  • compyutech
    compyutech about 7 years
    Thanks for answer. The place where we do domain wide deligation, its the same place where we create privatekey. But Using API call I am able to create/delete private key, Also update service account. I suspect there should be some way to enable domain wide delegation also.
  • scrthq
    scrthq about 7 years
    Not seeing anything about setting domain wide delegation on the API documentation, unfortunately