1

On Ubuntu 12.10, added the following entry to '/etc/logrotate.d' path:

# cat /etc/logrotate.d/tsdb
/home/logs/*dat {
        daily
        rotate 30
        compress
        missingok
        notifempty
        create 0664 nagios nagios
}

Below is how the '/etc/cron.daily/logrotate' file looks like:

# cat /etc/cron.daily/logrotate
#!/bin/sh

# Clean non existent log file entries from status file
cd /var/lib/logrotate
test -e status || touch status
head -1 status > status.clean
sed 's/"//g' status | while read logfile date
do
    [ -e "$logfile" ] && echo "\"$logfile\" $date"
done >> status.clean
mv status.clean status

test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate /etc/logrotate.conf

I expected the logs to rotate, but I do not see they being rotated. What could be that I am doing incorrectly here?

The status file does show that logrotate ran on the files in question, but I do not see any rotated logs:

# cat /var/lib/logrotate/status
logrotate state -- version 2
"/home/logs/service-perfdata.dat" 2013-11-26
"/home/logs/host-perfdata.dat" 2013-11-26

Also, here is how the '/etc/logrotate.conf' file looks like:

# cat /etc/logrotate.conf
# see "man logrotate" for details
# rotate log files weekly
weekly

# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones
create

# uncomment this if you want your log files compressed
#compress

# packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp, or btmp -- we'll rotate them here
/var/log/wtmp {
    missingok
    monthly
    create 0664 root utmp
    rotate 1
}

/var/log/btmp {
    missingok
    monthly
    create 0660 root utmp
    rotate 1
}

# system-specific logs may be configured here

Here is the output of the manual run of logrotate:

# /usr/sbin/logrotate -vd /etc/logrotate.conf

rotating pattern: /home/logs/*dat  after 1 days (30 rotations)
empty log files are not rotated, old logs are removed
considering log /home/logs/host-perfdata.dat
  log does not need rotating
considering log /home/logs/service-perfdata.dat
  log does not need rotating

1 Answer 1

2

The way logrotate handles log files initially, is non-intuitive:

  • The first time it runs, it will write the date and log file names out to the status file (it won't rotate any logs).
  • The next time it runs, it will check the status file to see if the logs should be rotated.

In your case, you saw that it checked the files in question, and wrote a status line for each the first time it ran. Any subsequent runs will use the date on that line and compare it against your log file dates to see if it should rotate. I suspect your files were dated Nov 26, and it checked on Nov 26, so they didn't need rotating. Either backdating your log files, or backdating the entry in the status file would get it to rotate the files for you.

Without an entry in the status file, even if the files need rotating it won't rotate them the very first time it's run, unless you use the -f (force) flag.

1
  • thank you Gerrat, that answer definitely helps my understanding of logrotate.
    – cog_n1t1v3
    Commented Apr 17, 2014 at 19:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.