Ok, it seems that it has nothing to do with logrotate. I think the errors you see are from fail2ban which is looking for these files. Try tu run manually the postscript from fail2ban in /etc/logrotate.d/fail2ban (o something like that) and you will see the errors.
man logrotate
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. The default value is -%Y%m%d. Note that also the character sep‐
arating log name from the extension is part of the dateformat string. The system clock must be set
past Sep 9th 2001 for %s to work correctly. Note that the datestamps generated by this format
must be lexically sortable (i.e., first the year, then the month then the day. e.g., 2001/12/01 is
ok, but 01/12/2001 is not, since 01/11/2002 would sort lower while it is later). This is because
when using the rotate option, logrotate sorts all rotated filenames to find out which logfiles are
older and should be removed.
Can anyone please tell me if "dateext" is correct? I want the log
filename to be something like "access.log-2010-12-04".
Insert a dateformat
directive to your configuration file, something like this:
/usr/local/nginx/logs/*.log {
daily
dateext
dateformat -%Y-%m-%d
...
One more thing: Can I do the log rotation every day on a specific time
(e.g. 11 pm)?
By default, logrotate is running via cron at 4 A.M:
/etc/cron.daily/logrotate
#!/bin/sh
/usr/sbin/logrotate /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0
You can move this file to somewhere and rename to logrotate.sh
, then create a new file in /etc/cron.d/
as belows:
0 23 * * * root /path/to/logrotate.sh
Best Answer
I'm not aware of any variables you can use if that's what you're looking for. However immediately after rotating the log, you should know precisely the name that the file has been rotated to based on the configuration you've set for the rotation (
/var/log/somefile.1
or the like).Perhaps it would be easier to answer if you described actual problem you're trying to solve?