Logrotate dateformat does not seem to support% H:% M:% S

I am new to logrotate. when configure goes into the "dateformat" property, it seems that logrotate does not support strftime "% H". here is the configuration: {daily rotate 2 size 3M missingok notifempty dateext dateformat -% Y% m% d_% H:% M:% S ...}

the rotating file format tends to look like this: uwsgi_dev.log-20150630_% H:% M:% S, but I want the exact “minutes and seconds of the hour”.

thanks

+7
date-format logrotate
source share
1 answer

Support for% H was added in version 3.9.0 . In earlier versions, logrotate did not support strftime "% H:

dateformat format_string: specify the extension for dateext using a notation similar to strftime (3). Only% Y% m% d and% s are allowed.

On the man logrotate page http://linux.die.net/man/8/logrotate

However, you can use %s in the dateformat line, which is the number of seconds since 1970-01-01. You can set dateformat -%Y%m%d-%s . This will create unique file names each time the log is rotated, so you can rotate the file several times a day. Unfortunately, the %s part will not be easy to read, but you can easily convert it back to a readable date using perl -e "print scalar(localtime(1451214849))" .

On some systems, the date program makes it easy to do this conversion using date -d @1451214849 (for example, GNU date ). On most systems (including, for example, Solaris date ), you might be lucky with a syntax like date -d "1970-01-01 + 1451214849 sec" . Note that Busybox date only supports the @ trick, but not the complex expressions of the second example.

+4
source share

All Articles