Solved

cron.daily problem

Posted on 2003-10-29
7
628 Views
Last Modified: 2013-11-13
I am confused about cron.daily in my RedHat 9.0 system.

If I see when it will be executed :

  # cat /etc/crontab
  SHELL=/bin/bash
  PATH=/sbin:/bin:/usr/sbin:/usr/bin
  MAILTO=root
  HOME=/

  # run-parts
  01 * * * * root run-parts /etc/cron.hourly
  02 4 * * * root run-parts /etc/cron.daily
  22 4 * * 0 root run-parts /etc/cron.weekly
  42 4 1 * * root run-parts /etc/cron.monthly

Then, the cron.daily will be executed everyday at 04:02 AM, right?

If I look into /etc/cron.daily, I saw this :

  # cd /etc/cron.daily
  # ls
  00-logwatch  0anacron  logrotate  makewhatis.cron  rpm  slocate.cron  tmpwatch

It runs "logrotate". So, in my understanding, the log files will be rotated EVERYDAY (depends on /etc/logrotate.conf).

Here is the content of /etc/logrotate.conf :

  # cat /etc/logrotate.conf
  weekly
  rotate 4
  create
  #compress
  include /etc/logrotate.d
  # no packages own wtmp -- we'll rotate them here
  /var/log/wtmp {
      monthly
      create 0664 root utmp
      rotate 1
  }

Then, logrotate will execute all configuration in /etc/logrotate.d, for example :

# cat /etc/logrotate.d/syslog
/var/log/messages /var/log/secure /var/log/maillog /var/log/spooler /var/log/boot.log /var/log/cron {
    sharedscripts
    postrotate
        /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
    endscript
}

But why, those logs are NOT rotated everyday ?

# ls -l /var/log
-rw-------    1 root     root         8693 Oct 30 08:01 cron
-rw-------    1 root     root        14349 Oct 26 04:02 cron.1
-rw-------    1 root     root        14464 Oct 19 04:02 cron.2
-rw-------    1 root     root         7153 Oct 12 04:02 cron.3
-rw-------    1 root     root        10162 Oct 30 07:38 messages
-rw-------    1 root     root        61375 Oct 26 02:48 messages.1
-rw-------    1 root     root        51918 Oct 19 01:38 messages.2
-rw-------    1 root     root        51224 Oct  9 21:41 messages.3

See the date? In my understanding above, it should be rotated everyday. But why NOT ?

I checked in 3 RedHat 9.0 boxes, and all are the same situation. Am I missing something or misunderstood ?

Because I tried to run webalizer through logrotate of httpd :

/var/log/httpd/*log /home/www/mydomain.com/logs/*log {
    missingok
    notifempty
    sharedscripts
    prerotate
        /usr/bin/webalizer
    endscript
    postrotate
        /bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true
    endscript
}

But with this situation, it does not executed :(

So I just confused. Please help.

Thank you
0
Comment
Question by:nova2002
  • 2
  • 2
  • 2
  • +1
7 Comments
 

Expert Comment

by:AlanBell
ID: 9648459
This snippet from the logrotate manpage should explain whats going on:

weekly Log files are rotated if  the  current  weekday  is
              less  then  the  weekday of the last rotation or if
              more then a week has passed since  the  last  rota-
              tion. This is normally the same as rotating logs on
              the first day of the week, but it works  better  if
              logrotate is not run every night.

Alan.
0
 

Author Comment

by:nova2002
ID: 9648537
So, if I want to execute specific logrotate daily, can I overwrite that ?

For example :

/var/log/httpd/*log /home/www/mydomain.com/logs/*log {
    daily
    missingok
    notifempty
    sharedscripts
    prerotate
        /usr/bin/webalizer
    endscript
    postrotate
        /bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true
    endscript
}

Will this works?
0
 

Expert Comment

by:AlanBell
ID: 9648602
What I would do is add that snippet above into a file /etc/logrotate.d/ called http, web or whatever you want.

Because the line "include /etc/logrotate.d" points to a directory logrotate will include all files in that directory and because your "daily" option is specific to those log files it will override the global "weekly" option.

Alan.
0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
LVL 1

Expert Comment

by:Kubrik
ID: 9649078
>> Because I tried to run webalizer through logrotate of httpd :

What do you want to do?
Starting webalizer daily?

Create a file (chmoded +x) under /etc/cron.daily with this line:

#!/bin/sh
/usr/bin/webalizer -c /etc/webalizer/yourconf.conf
0
 

Author Comment

by:nova2002
ID: 9650494
Kubrik,
Yes, basically I want to do that.

But I also want my apache logs will be ROTATED. So, I came up with the idea above, using logrotate to run webalizer. Because I want to make sure that the webalizer will process the correct log.

0
 
LVL 1

Accepted Solution

by:
Kubrik earned 45 total points
ID: 9650693
Ok, then add
 daily
as you had wrote before.

Because when no "daily" or "weekly" or "monthly" is specified in a directive file like apache one:

/var/log/httpd/*log /home/www/mydomain.com/logs/*log {
    missingok
    notifempty
    sharedscripts
    prerotate
        /usr/bin/webalizer
    endscript
    postrotate
        /bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true
    endscript
}

default is WEEKLY taken from logrotate.conf :

# cat /etc/logrotate.conf
  weekly   <-----------------------------
  rotate 4
  create
  #compress
  include /etc/logrotate.d

bye.
0
 
LVL 20

Expert Comment

by:Gns
ID: 9650762
Basically, what you suggest (the daily modification) would do what you want. Separating the different "domains"(:-) of httpd logs into separate logrotate.d files (as AlanBell suggests) would be nicem since then you'd be able to retain the "slow rotation" of the main service logs. Or running webalizer from a separate cronjob (as Kubrik suggests)  would also work nicely (keeping both main logs and mydomain.com logs at "weekly" rotations).
But as said, you'd be fine with the "daily". (I'm buting in, since I suggested logrotate to nova2002 in http://www.experts-exchange.com/Operating_Systems/Linux/Q_20780811.html ...)

-- Glenn
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I have been scripting applications way too long and can never remember how to create an ISS file.  So I decided to write this article to act as my own knowledge base for future reference, and hope you will also benefit. An ISS file is a response …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now