logrotate with /etc/logrotate.conf file


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users logrotate with /etc/logrotate.conf file
# 1  
Old 10-16-2009
logrotate with /etc/logrotate.conf file

Hi there,

I want to rotate the logfiles which are located in /var/log/jboss/tomcat*

so I have created a file named as 'tomat' in /etc/logrotate.d/tomcat with the following content.
Code:
# cat /etc/logrotate.d/tomcat
/var/log/jboss/tomcat_access_log*.log {
        daily
        nocreate
        rotate 1
        compress
        missingok
        postrotate
                find /var/log/jboss/ -iname 'tomcat_access_log*.gz' -type f -mtime +4 -exec rm -f \{\} \;
        endscript
}

As of now, /var/log/jboss has two tomcat access log files.

Code:
$ls -l /var/log/jboss
-rw-r--r-- 1 root root 46546 Oct 14 10:22 tomcat_access_log.2009-10-14.log
-rw-r--r-- 1 root root 46546 Oct 15 14:10 tomcat_access_log.2009-10-15.log

Content of default logrotate configuration file /etc/logrotate.conf
Code:
# cat /etc/logrotate.conf
# Let's do daily rotations on this system.
daily
rotate 30
create
compress
include /etc/logrotate.d
/var/log/wtmp {
        monthly
        create 0664 root utmp
        rotate 1
}

Executed the following command :

Code:
$ /usr/sbin/logrotate -v /etc/logrotate.conf
rotating pattern: /var/log/jboss/tomcat_access_log*.log  after 1 days (1 rotations)
empty log files are rotated, old logs are removed
considering log /var/log/jboss/tomcat_access_log.2009-10-14.log
  log does not need rotating
considering log /var/log/jboss/tomcat_access_log.2009-10-15.log
  log does not need rotating
not running postrotate script, since no logs were rotated
not running postrotate script, since no logs were rotated

If you see the above logs, it doesnt rotate any log files...
Code:
$ls -l /var/log/jboss
-rw-r--r-- 1 root root 46546 Oct 14 10:22 tomcat_access_log.2009-10-14.log
-rw-r--r-- 1 root root 46546 Oct 15 14:10 tomcat_access_log.2009-10-15.log

When execute the same command with -f (force) option it is rotating and compressing the file..

My Doubt is :

I have logrotate to execute in the cron.daily.
Code:
# cat /etc/cron.daily/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
chmod a+r /var/log/messages

I could able to see from the cron logs cron.daily was executed. But when I saw /var/log/jboss directory log files are there with out compressing and rotating.. But when I execute manually using -f option its rotation.

How to resolve this issue ? Any help is appreciated.
# 2  
Old 10-16-2009
I'd try increasing the:
rotate 1
to a larger number?
I know 1 means "1 extra" log file but I have never seen such a low number used.
# 3  
Old 10-17-2009
The "problem" is that logrotate doesn't immediately switch any logs, but only after the rotation time for a file (in your case 1 day) has passed since it was first seen. So if you have 2 files, for the 14th and 15th of the month, and logrotate first sees them on the 16th of the month, they'll normally get rotated on the 17th.

With applications separating their logs by themselves, it's probably easier to work with find, eg:
Code:
find /var/log/jboss -type f -name '*.log' -mtime +1 -exec gzip -9 '{}' ';'
find /var/log/jboss -type f -name '*.log.gz' -mtime +4 -exec rm -f '{}' ';'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Logrotate 0 byte file

Hello, For various reasons I decided to rebuild my log server on a new microSD. To simplify matters I restored a backed up copy of the appropriate config files and uploaded them to the new log server once syslog-ng was setup. The issue I am running into now is when logrotate compresses the log... (3 Replies)
Discussion started by: MyUserName7000
3 Replies

2. Solaris

How to logrotate a file after X days with logadm?

Hi Guys - We have the /var/adm/pacct file currently configured to log rotate using logadm - here is the entry in logadm.conf: /var/adm/pacct -C 0 -N -P 'Wed Oct 23 08:00:00 2013' -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never Just want to ask if it would like possible to... (1 Reply)
Discussion started by: akaterasu
1 Replies

3. AIX

Logrotate.conf

Hey Admins, I have installed logrotate on AIX server. I want to configure it for 1. /var/log/messages – keep 90 days, i.e., weekly rotate 13 2. Syslog – keep 90 days i.e., weekly rotate 13 3. Wtmp – keep 90 days i.e., weekly rotate 13 4. Sulog – keep 90 days i.e., weekly rotate 13 What... (1 Reply)
Discussion started by: snchaudhari2
1 Replies

4. AIX

Logrotate - /etc/logrotate.conf does't exist

Hi Admins. I have installed logrotate rpm on Aix 6.1. After the installation of rpm, I don't find /etc/logrotate.conf file and /etc/logrotate.d dir . The config file is located in /opt/freeware/etc/logrotate.conf. When I ran logrotate -v /opt/freeware/etc/logrotate.conf I get below... (2 Replies)
Discussion started by: snchaudhari2
2 Replies

5. Shell Programming and Scripting

Logrotate - I am not able to rotate files using logrotate

I have written script which is working in Home directory perfectly and also compressing log files and rotating correctly. But, when i try to run script for /var/log/ i am able to get compressed log files but not able to get rotation of compressed log files. Please suggest. I am using below command... (5 Replies)
Discussion started by: VSom007
5 Replies

6. Red Hat

File is missing after logrotate!!

I am having a requirement to rotate the my application logs dailay as it is keep on writiing to single file and below is the logrotate function which I am using, cat /apps/bmc/bmtm/QPasa_logrotate.conf /apps/bmc/bmtm/all_events.log /apps/bmc/bmtm/history_association.log { missingok ... (1 Reply)
Discussion started by: sandyrajh
1 Replies

7. UNIX for Dummies Questions & Answers

Explain this logrotate file

Very silly question .. I deleted it .. Please delete this thread too . (0 Replies)
Discussion started by: stunn3r
0 Replies

8. Red Hat

Some questions about Logrotate.conf

Hi all, I have to configure the logrotate.conf file on some Linux RedHat servers. So, by default I seen the file is as follow: # see "man logrotate" for details # rotate log files weekly weekly # keep 4 weeks worth of backlogs rotate 4 # create new (empty) log files after rotating... (5 Replies)
Discussion started by: idro
5 Replies

9. UNIX for Dummies Questions & Answers

how to set size in logrotate.conf

Hi,guys: recently,i am puzzled by a question .when i create a new file named by /etc/logrotate.d/debug. The cont. is listed as follow: /var/log/debug { rotate 3 missingok notifempty size=2k prerotate /bin/kill -HUP `cat... (0 Replies)
Discussion started by: icehero
0 Replies

10. UNIX for Advanced & Expert Users

logrotate.conf

I changed the logrotate.conf file to make a new log file to be automatically rotated daily. But after a night, I have not seen the rotated file. When does this rotation happen? I mean what is the exact time? In addition, do I have to restart what deamon to make the change take effect? (10 Replies)
Discussion started by: fredao
10 Replies
Login or Register to Ask a Question