Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have the following file in /etc/logrotate.d:

/usr/share/apache-tomcat/logs/*.access {
nodateext
copytruncate
daily
rotate 7
notifempty
postrotate
EXT=`date --date='-1 day' +%Y-%m-%d`
/bin/gzip $1.1
mv $1.1.gz  $1.$EXT.log.gz
endscript
create 0640 tomcat tomcat
}

It should take a file servername.access and move it to servername.access.2013.02.24.log.gz

When I run manually sudo /usr/sbin/logrotate -v /etc/logrotate.d/tomcat it works From inside the cron daily it does not work

contents of /var/lib/logrotate.status

logrotate state -- version 2
"/var/log/yum.log" 2013-1-1
"/var/log/up2date" 2012-12-12
"/var/log/sssd/*.log" 2012-12-12
"/var/log/dracut.log" 2013-1-1
"/var/log/httpd/*log" 2013-2-12
"/var/log/wtmp" 2012-12-12
"/var/log/spooler" 2013-2-24
"/usr/share/apache-tomcat/logs/AWS001.access" 2013-2-24
"/var/log/btmp" 2013-2-12
"/var/log/rhsm/rhsmcertd.log" 2013-2-24
"/var/log/maillog" 2013-2-24
"/var/log/php-fpm/error.log" 2013-2-24
"/var/log/cups/*_log" 2012-12-12
"/var/log/secure" 2013-2-24
"/var/log/rhsm/rhsm.log" 2013-2-24
"/var/log/messages" 2013-2-24
"/var/account/pacct" 2012-12-12
"/var/log/cron" 2013-2-24

output of /var/log/cron:

Feb 24 00:48:01 AWS001 run-parts(/etc/cron.daily)[13433]: starting logrotate
Feb 24 00:48:02 AWS001 run-parts(/etc/cron.daily)[13457]: finished logrotate

Has somebody an idea?

share|improve this question
    
Have you checked user/group permissions on the logs? Can the user running logrotate access them and do something with them? –  JakeGould Feb 25 '13 at 3:54
    
Since logrotate write to the folder from outside the cron, I don't think that is the problem. I nevertheless chmod the log folder to +w, I will let you know tomorrow if it helped. –  ashersz Feb 25 '13 at 6:44

3 Answers 3

I finally got it to work

sudo crontab -u root -l (list jobs for user root in cron)
There was no jobs
sudo crontab -u root -e (edit crontab)
@daily /usr/sbin/logrotate -v /etc/logrotate.d/tomcat  >/dev/null 2>&1
save the file
sudo crontab -u root -l
one job for user root

I also added full paths in /etc/logrotate.d/tomcat as indicated by user quanta

Note: when you cat /etc/crontab it is still empty

I found my job in file /var/spool/cron/root
Thanks to all who answered

share|improve this answer

When I run manually sudo /usr/sbin/logrotate -v /etc/logrotate.d/tomcat it works From inside the cron daily it does not work

Keep in mind that you should always use the absolute path in the cron, so try this:

EXT=`/bin/date --date='-1 day' +%Y-%m-%d`
/bin/gzip $1.1
/bin/mv $1.1.gz $1.$EXT.log.gz
share|improve this answer
    
I am trying your code –  ashersz Feb 25 '13 at 6:46

logrotate -d /path/tologrotate.conf

(NB: not your fragment file, the top level one that includes it)

Output of that can be helpful.

excerpt of sudo /usr/sbin/logrotate -d /etc/logrotate.conf after I set the date one day backwards inside /var/lib/logrotate.status (otherwise it says nothing to rotate)

rotating pattern: /usr/share/apache-tomcat/logs/*.access  after 1 days (7 rotations)
empty log files are not rotated, old logs are removed
considering log /usr/share/apache-tomcat/logs/AWS001.access
  log needs rotating
rotating log /usr/share/apache-tomcat/logs/AWS001.access, log->rotateCount is 7
dateext suffix '-20130225'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
renaming /usr/share/apache-tomcat/logs/AWS001.access.7 to /usr/share/apache-tomcat/logs/AWS001.access.8 (rotatecount 7, logstart 1, i 7), 
renaming /usr/share/apache-tomcat/logs/AWS001.access.6 to /usr/share/apache-tomcat/logs/AWS001.access.7 (rotatecount 7, logstart 1, i 6), 
renaming /usr/share/apache-tomcat/logs/AWS001.access.5 to /usr/share/apache-tomcat/logs/AWS001.access.6 (rotatecount 7, logstart 1, i 5), 
renaming /usr/share/apache-tomcat/logs/AWS001.access.4 to /usr/share/apache-tomcat/logs/AWS001.access.5 (rotatecount 7, logstart 1, i 4), 
renaming /usr/share/apache-tomcat/logs/AWS001.access.3 to /usr/share/apache-tomcat/logs/AWS001.access.4 (rotatecount 7, logstart 1, i 3), 
renaming /usr/share/apache-tomcat/logs/AWS001.access.2 to /usr/share/apache-tomcat/logs/AWS001.access.3 (rotatecount 7, logstart 1, i 2), 
renaming /usr/share/apache-tomcat/logs/AWS001.access.1 to /usr/share/apache-tomcat/logs/AWS001.access.2 (rotatecount 7, logstart 1, i 1), 
renaming /usr/share/apache-tomcat/logs/AWS001.access.0 to /usr/share/apache-tomcat/logs/AWS001.access.1 (rotatecount 7, logstart 1, i 0), 
copying /usr/share/apache-tomcat/logs/AWS001.access to /usr/share/apache-tomcat/logs/AWS001.access.1
truncating /usr/share/apache-tomcat/logs/AWS001.access
running postrotate script
running script with arg /usr/share/apache-tomcat/logs/AWS001.access: "
EXT=`/bin/date --date='-1 day' +%Y-%m-%d`
/bin/gzip $1.1
/bin/mv $1.1.gz  $1.$EXT.log.gz
"
removing old log /usr/share/apache-tomcat/logs/AWS001.access.8
error: error opening /usr/share/apache-tomcat/logs/AWS001.access.8: No such file or directory
share|improve this answer
1  
sudo /usr/sbin/logrotate -d /etc/logrotate.conf –  ashersz Feb 25 '13 at 6:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.