Solved

Question on Cronjobs/Logrotate in Linux

Posted on 2011-03-07
7
1,244 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
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…
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.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

760 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

18 Experts available now in Live!

Get 1:1 Help Now