nova2002
asked on
cron.daily problem
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/log s/*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
If I see when it will be executed :
# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:
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/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
ASKER
So, if I want to execute specific logrotate daily, can I overwrite that ?
For example :
/var/log/httpd/*log /home/www/mydomain.com/log s/*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?
For example :
/var/log/httpd/*log /home/www/mydomain.com/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?
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.
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.
>> 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.co nf
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.co
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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 https://www.experts-exchange.com/questions/20780811/Rotating-log.html ...)
-- Glenn
But as said, you'd be fine with the "daily". (I'm buting in, since I suggested logrotate to nova2002 in https://www.experts-exchange.com/questions/20780811/Rotating-log.html ...)
-- Glenn
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.