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.
Benedikt köppel
source share