logrotate in SUSE Enterprise Server

1

I can't manage to work this dummy config file (I placed it in etc/logrotate.d):

/var/log/test_log/mylogfile {
copytruncate
dateext
rotate 3
compress
missingok
size=+2
}

I write to the log (echo "hello world" > /var/log/test_log/mylogfile) but it's just not working.

Doing cat /etc/crontab shows:

# check scripts in cron.hourly, cron.daily, cron.weekly, and cron.monthly
#
-*/15 * * * *   root  test -x /usr/lib/cron/run-crons && /usr/lib/cron/run-crons >/dev/null 2>&1

I later redirected the output to in this way:

-*/15 * * * *   root  test -x /usr/lib/cron/run-crons && /usr/lib/cron/run-crons > /var/log/test_log/log_logrotate

But nothing happened.

Should I add another line in the etc/crontab to force the cron.dayly to happen kind of like in Ubuntu:

25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )

or the problem may be in the /usr/lib/cron/run-crons file??

I am under SUSE Linux Enterprise Server 11 SP2

gugol

Posted 2015-02-12T13:40:37.813

Reputation: 121

how often you want to rotate ? – Darek – 2015-02-12T13:48:18.847

@tdi I would like to do it dayly but my example is just a dummy example. I can't run any logrotate file. Anyway the size option should trigger the logrotate, shouldn't it? – gugol – 2015-02-12T15:00:45.453

see my answer below. – Darek – 2015-02-12T15:06:55.943

Answers

1

I think I found an answer to my question. The issue was tricky because "the newer Cron versions of Linux may run abit differently than in older versions" to what I was used to.

It seems now Cron consists of the script usr/lib/cron/run-crons, which checks whether cron.dayly in /var/spool/cron/lastrun/ is older than one day (By default it checks if it is more than or exactly 1440 minutes since lastrun). Or if we want the cron.dayly to run at a fixed time we should set the DAILY_TIME variable in the /etc/sysconfig/cron file to a time (i.e:"12:00") and it will be run at that time dayly (within 15minutes).

Note (from the /etc/sysconfig/cron comments):Due to the fact that cron script runs only every 15 minutes, it will only run on xx:00, xx:15, xx:30, xx:45, not at the accurate time you set.

I found the answer here:

gugol

Posted 2015-02-12T13:40:37.813

Reputation: 121

The only thing that still confuses me is the - at the beginning of the crontab task:

-*/15 * * * * root test -x /usr/lib/cron/run-crons && /usr/lib/cron/run-crons >/dev/null 2>&1 – gugol – 2015-02-12T16:51:49.797

0

logrotate runs either when time period is given weekly, daily and so on, or in the case of size when filesize exeeds the given size.

Just put there size=2, instead of size=+2, and it should work.

size size

Log files are rotated when they grow bigger then size bytes. If size is followed by M, the size if assumed to be in megabytes. If the k is used, the size is in kilobytes. So size 100, size 100k, and size 100M are all valid.

Darek

Posted 2015-02-12T13:40:37.813

Reputation: 886

No, my configuration file is fine. If I run /usr/sbin/logrotate /etc/logrotate.conf it does what it is suppossed to do so I guess the problem seems to be in the etc/crontab file, doesn't it? – gugol – 2015-02-12T15:15:24.810

just try this: logrotate YOUR CONFIG – Darek – 2015-02-12T15:16:17.507

that is exactly what I did: /usr/sbin/logrotate /etc/logrotate.conf. And as I said before that do work, but what I want is the logrotate to be done automatically. – gugol – 2015-02-12T15:34:53.183