Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Question on Cronjobs/Logrotate in Linux

Posted on 2011-03-07
7
Medium Priority
?
1,270 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 750 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
Ready for your healthcare security check-up?

In the past few years, healthcare organizations have become a prime target for advanced attacks. Does your organization have what it needs to defend itself? Schedule your healthcare security check-up today and download our free Healthcare Security Resource Kit today!

 

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
 
LVL 4

Accepted Solution

by:
l4ncel0t earned 750 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You ever wonder how to backup Linux system files just like Windows System Restore?  Well you can use Timeshift in Linux to perform those similar action.  This tutorial will show you how to backup your system files and keep regular intervals. Note…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

916 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