Solved

Question on Cronjobs/Logrotate in Linux

Posted on 2011-03-07
7
1,246 Views
Last Modified: 2012-05-11
Hello,

In many of the Linux servers in our environment, we noticed the logfiles such as /var/log/messages, /var/log/secure aren't getting rotated for several months though the config file looks fine (/etc/logrotate.conf). When I check the /etc/crontab, I see the following entries:


[root@orallm72 etc]# 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
[root@orallm72 etc]# cd /etc/cron.daily
[root@orallm72 cron.daily]# ls
00webalizer  0logwatch  cups             logrotate        mlocate.cron  rpm         tmpwatch
0anacron     certwatch  inn-cron-expire  makewhatis.cron  prelink       tetex.cron  tripwire-check
[root@orallm72 cron.daily]# cat logrotate
#!/bin/sh

/usr/sbin/logrotate /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
    /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0
[root@orallm72 cron.daily]#

My Questions:

1. What are that entry "run-parts", what does it do ?
2. How can I ensure the "cron.daily" is getting executed without fail everyday and it is executing the 'logrotate' command?

Please let me know if you have any questions.
0
Comment
Question by:ashsysad
  • 4
  • 2
7 Comments
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 250 total points
ID: 35062165
1.  run-parts is a utility that executes all the files in the specified directory

2. Check your cron log.  Locations vary depending on your system, but try /var/log/cron.log

Also check the contents of /etc/logrotate.conf and the /etc/logrotate.d directory to see what's configured to be rotated.
0
 
LVL 4

Expert Comment

by:l4ncel0t
ID: 35062235
Hello
did you tried that
/usr/sbin/logrotate /etc/logrotate.conf
manually ?
0
 

Author Comment

by:ashsysad
ID: 35062589
Yes, when i try manually with '-f' option, it works fine. But cron.daily is not seems to be executing it daily.
I just want to ensure that in all the servers, the logs are getting rotated properly.

I just created a log file that can be put in /etc/logrotate.conf file. But how would I ensure that cron.daily is executing this properly. Its not practically possible to run "logrotate" command manually everyday.


/var/log/messages {
        daily
        create
        missingok
        notifempty
        size 1M
        rotate 4
        nomail
        postrotate
                killall -HUP syslogd
        endscript
}
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:ashsysad
ID: 35062905
To put my question simple....in all the Linux servers in our environment, how can I check and ensure that Log files are getting rotated properly ?  Cron log may gives me some information but its not practically possible for me to analyse log files in each and every server. We have FUNC server in our setup, using which I can execute some commands simultaneously in all the Linux servers and get the output. However checking log files would be pain.
0
 

Author Comment

by:ashsysad
ID: 35062921
0
 
LVL 4

Accepted Solution

by:
l4ncel0t earned 250 total points
ID: 35067192
Can you launch  logrotate script in cron.daily ?
Is cron daemon runing ?

If every parts work you shoudn't have problem like that

I usually monitor crond + filesystem usage for this type of problem (with zabbix)

To be more precise you need to know what is the problem with your current configuration

For your logfile maybee you can check the creation date with find.
If ceration date is older than your retention policy in logrotate you likely have a problem


0
 

Author Closing Comment

by:ashsysad
ID: 35272565
Thanks for your ideas.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

929 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

17 Experts available now in Live!

Get 1:1 Help Now