2

Title says it all, I have a log rotate set up daily for some rather large log files. Sometimes we can generate 3 of these a day, sometimes we only generate 1, they're each about 500MB. Is there a way to keep date modified of the file after a log rotate? It's a lot easier to note those dates at a glance when looking for something in the logs, than to head and tail each file looking for dates.

T Jones
  • 21
  • 2

2 Answers2

2

You can configure log rotate to append the date to rotated log files (by specifying dateext option).

Slavisa
  • 29
  • 2
2

Two options immediately spring to mind:

  • You make logrotate append the date to rotated log files, by using the option dateext. If you're doing the rotation shortly after midnight, you may want the log file to have the name of the previous day; you can do this with the option dateyesterday.
  • You can use the postrotate to run a command, such as touch -m yesterday after the file has been rotated, to change the file's modify time to the previous day.

man logrotate.conf and info coreutils 'touch invocation' are good places to start looking for more information.

Jenny D
  • 27,780
  • 21
  • 75
  • 114