Solved

cron.daily problem

Posted on 2003-10-29
7
637 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Fine Tune your automatic Updates for Ubuntu / Debian
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 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