Search This Blog

Friday, April 13, 2012

HowTo: The Ultimate Logrotate Command Tutorial with 10 Examples

HowTo: The Ultimate Logrotate Command Tutorial with 10 Examples:


5. Logrotate dateext option: Rotate the old log file with date in the log filename

$ cat logrotate.conf
/tmp/output.log {
        size 1k
        copytruncate
        create 700 bala bala
        dateext
        rotate 4
        compress
}
After the above configuration, you’ll notice the date in the rotated log file as shown below.
$ ls -lrt /tmp/output*
-rw-r--r--  1 bala bala 8980 2010-06-09 22:10 output.log-20100609.gz
-rwxrwxrwx 1 bala bala     0 2010-06-09 22:11 output.log
This would work only once in a day. Because when it tries to rotate next time on the same day, earlier rotated file will be having the same filename. So, the logrotate wont be successful after the first run on the same day.
Typically you might use tail -f to view the output of the log file in realtime. You can evencombine multiple tail -f output and display it on single terminal.

No comments:

Post a Comment