войти в SUSE Enterprise Server

2375
gugol

Я не могу работать с этим фиктивным файлом конфигурации (я поместил его в etc / logrotate.d):

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

Я пишу в журнал (echo "hello world"> / var / log / test_log / mylogfile), но он просто не работает.

Выполнение cat / etc / crontab показывает:

# 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 

Позже я перенаправил вывод на таким образом:

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

Но ничего не случилось.

Должен ли я добавить еще одну строку в etc / crontab, чтобы cron.dayly происходил примерно так же, как в Ubuntu:

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

или проблема может быть в файле / usr / lib / cron / run-crons ??

Я нахожусь под SUSE Linux Enterprise Server 11 SP2

1
как часто вы хотите вращаться? Darek 9 лет назад 0
@tdi Я бы хотел делать это каждый день, но мой пример - всего лишь фиктивный пример. Я не могу запустить любой файл logrotate. В любом случае, опция размера должна вызывать логротейт, не так ли? gugol 9 лет назад 0
см. мой ответ ниже. Darek 9 лет назад 0

2 ответа на вопрос

1
gugol

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:

Единственное, что меня все еще смущает, это - в начале задачи crontab: `- * / 15 * * * * root test -x / usr / lib / cron / run-crons && / usr / lib / cron / run -crons> / dev / null 2> & 1` gugol 9 лет назад 0
0
Darek

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.

Нет, мой файл конфигурации в порядке. Если я запускаю `/ usr / sbin / logrotate / etc / logrotate.conf`, он делает то, что предполагается сделать, поэтому я предполагаю, что проблема, похоже, в файле etc / crontab, не так ли? gugol 9 лет назад 0
просто попробуйте это: `logrotate YOUR CONFIG` Darek 9 лет назад 0
это именно то, что я сделал: `/ usr / sbin / logrotate / etc / logrotate.conf`. И, как я уже говорил, работайте, но я хочу, чтобы логротат выполнялся автоматически. gugol 9 лет назад 0