logrotate dateformat seems not supporting %H:%M:%S

浪子不回头ぞ 提交于 2019-12-06 19:02:53

问题


I am newer to logrotate. when the configure comes to the property "dateformat",it seems that logrotate doesn't support strftime "%H" . here is the config:

{
    daily
    rotate  2
    size 3M
    missingok
    notifempty
    dateext
    dateformat -%Y%m%d_%H:%M:%S
    ...
}

the rotated file format tend to look like : uwsgi_dev.log-20150630_%H:%M:%S, but I want the exact "hour minutes and seconds".

thanks


回答1:


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 the notation similar to strftime(3) function. Only %Y %m %d and %s specifiers are allowed.

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

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

On some systems, the date program allows to do such conversion easily with date -d @1451214849 (e.g. GNU date). On most systems (including e.g. Solaris date), you may have luck with syntax like date -d "1970-01-01 + 1451214849 sec". Note that Busybox date supports only the @ trick but not complex expressions of the second example.



来源:https://stackoverflow.com/questions/31132995/logrotate-dateformat-seems-not-supporting-hms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!