-3

On a CentOS 6.x I created a simple service called logtraffic which, when started, appends the output of a tcpdump command to a log file at /var/log/logtraffic/logtraffic.log.

I want to achieve the following regarding that log:

  • have that log rotated daily at midnight

  • keep the latest 7 logs and delete the older ones

For this, I've done the following:

  • commented the following line from /etc/anacrontab

1 5 cron.daily nice run-parts /etc/cron.daily

  • added the following cron job: @midnight /etc/cron.daily/logrotate

  • created the file /etc/logrotate.d/logtraffic with the content:

    /var/log/logtraffic/*log { daily rotate 7 create dateext missingok notifempty sharedscripts postrotate /sbin/service logtraffic restart > /dev/null 2>/dev/null || true endscript }

Looks like the log is properly truncated at midnight as the timestamps displayed in logtraffic.log prove that.

The problem is that no other older log file is present in that folder. I was expecting to have older logs with a suffix like YYYYMMDD but there are none.

What am I doing wrong?

Ciprian Stoica
  • 147
  • 2
  • 10
  • 2
    What does a manual run of logrotate tell you? – womble Jul 08 '16 at 07:25
  • I ran: 'logrotate -d /etc/logrotate.conf' and it gave me the following: 'rotating pattern: /var/log/logtraffic/*log after 1 days (7 rotations) empty log files are not rotated, old logs are removed considering log /var/log/logtraffic/logtraffic.log log does not need rotating not running postrotate script, since no logs were rotated' – Ciprian Stoica Jul 11 '16 at 11:28
  • By the way, I see that I got -3 (so far) for my question. I always try to improve the quality of both my answers and my questions on the Stack Exchange sites. Therefore, I would appreciate a short explanation beside a -1. I'm not upset or anything like this. I just want to learn. Cheers. :-) – Ciprian Stoica Jul 11 '16 at 11:35

1 Answers1

0

I finally managed to fix the issue. I changed the content of /etc/logrotate.d/logtraffic with the following code:

/var/log/logtraffic/*log {
    daily
    rotate 7
    create
    dateext
    missingok
    notifempty
    sharedscripts
    prerotate
        /sbin/service logtraffic stop > /dev/null 2>/dev/null || true
    endscript
    postrotate
        /sbin/service logtraffic start > /dev/null 2>/dev/null || true
    endscript
}

I still don't understand why it didn't work with my previous settings, but at least it is fixed now.

Ciprian Stoica
  • 147
  • 2
  • 10