1

I have a logrotate running on Aws ec2 instance which is trying to rotate logs under /var/log/tomcat8/ every hour. I have below configuration under /etc/logrotate.d/rotate_tomcat:

"/var/log/tomcat8/localhost_access_log.*-*-*.txt" "/var/log/tomcat8/catalina.*-*-*.log" "/var/log/tomcat8/agent-log.*-*-*.json" "/var/log/tomcat8/ldap-query-log.*-*-*.*.json" {
    copytruncate
    size 1k
    rotate 5
    compress
    missingok
    create 0644 tomcat tomcat
}

When I run this manually, it works as expected. But when I run this as crond, it doesn't do anything. Below is my crond config under /etc/crond.d/accessLogDeletion

*/2 * * * * root logrotate /etc/logrotate.d/rotate_tomcat

Any inputs are appreciated.

cubick
  • 139
  • 7
krish
  • 13
  • 2

1 Answers1

4

The problem is with PATH in cron session.

/bin/sh: 1: logrotate: not found

You can fix with full path of command:

*/2 * * * * root /usr/sbin/logrotate /etc/logrotate.d/rotate_tomcat >> /var/log/myCron.log  2>&1

or with PATH env at start of cron script:

PATH=/usr/sbin:/usr/bin:/sbin:/bin

*/2 * * * * root logrotate /etc/logrotate.d/rotate_tomcat >> /var/log/myCron.log  2>&1

It's a good practice to log output of cron commands like above.