cancel
Showing results for 
Search instead for 
Did you mean: 

Logrotate is failing

 
SOLVED
Go to solution
Miguel Silva Rentes
Regular Advisor

Logrotate is failing

Hi everyone!

I'm unable to successfully use logrotate to rotate syslog.log files. The problem is that logrotate is always creating a syslog.log.1 file and won't continue to create successive syslog.log.2, syslog.log.3, ..., syslog.log.N files, and it's not compressing these files either. Here's my /opt/logrotate/etc/logrotate.conf file:

create
compress
rotate 10

# uncomment this if you want your log files compressed
# compress

# packages drop log rotation information into this directory
# include /opt/logrotate/etc

# no packages own wtmp -- we'll rotate them here
/var/adm/wtmp {
monthly
create 0664 adm adm
rotate 1
}

# cat syslog
/var/adm/syslog/syslog.log {
rotate 10
daily
create
ifempty
noolddir
compress
create 640 root root
postrotate
/bin/kill -HUP `cat /var/run/syslog.pid`
endscript
}

# cat maillog
/var/adm/syslog/mail.log {
rotate 5
weekly
compress
}

And in /var/spool/cron/crontabs/root I have this configuration:

00 9 * * * /opt/logrotate/bin/logrotate /opt/logrotate/etc/logrotate.conf

If I run logrotate with -v I get the following output:

reading config file /opt/logrotate/etc/logrotate.conf
reading config info for /var/adm/wtmp
reading config info for /var/adm/syslog/syslog.log
reading config info for /var/adm/syslog/mail.log
Handling 3 logs
rotating pattern: /var/adm/wtmp monthly (1 rotations)
empty log files are rotated old logs are removed
errors will be mailed to miguel.rentes@efacec.pt
rotating pattern: /var/adm/syslog/syslog.log after 1 days (10 rotations)
empty log files are rotated old logs are removed
errors will be mailed to miguel.rentes@efacec.pt
rotating pattern: /var/adm/syslog/mail.log weekly (5 rotations)
empty log files are rotated old logs are removed

From here I can see that logrotate is removing my old logs, but I can't seem to understand why because I'm telling it to rotate 10 files in logrotate.conf.

Do you have any suggestions why this is happening? I also want to compress all log files but this is not happening either (gzip is in /usr/contrib/bin which is on the PATH).

Best regards and thanks in advance,

Miguel Rentes
11 REPLIES
Dennis Handly
Acclaimed Contributor

Re: Logrotate is failing

>gzip is in /usr/contrib/bin which is on the PATH.

This isn't in the default path for cronjobs.
How do you tell logrotate that you want to use gzip and where it is?
Miguel Silva Rentes
Regular Advisor

Re: Logrotate is failing

Hi Dennis!

From the man page I can read:

compress
Old versions of log files are compressed with gzip. See also nocompress.

I didn't know I have to include any option to tell logrotate where to find gzip, I assumed it would find it from the PATH. The verbose output is not explicit either on this matter. So, how can I tell logrotate to use gzip? Isn't gzip used by default? And what about logrotate not rotating 10 times syslog.log?

Best regards,

Miguel Rentes
Dennis Handly
Acclaimed Contributor

Re: Logrotate is failing

>I assumed it would find it from the PATH.

It can't if you are using cron and don't explicitly set it.
Have you tried executing the command from your shell:
/opt/logrotate/bin/logrotate /opt/logrotate/etc/logrotate.conf
Miguel Silva Rentes
Regular Advisor

Re: Logrotate is failing

Hi Dennis!

But how can I configure logrotate to use gzip then? If I run:

/opt/logrotate/bin/logrotate /opt/logrotate/etc/logrotate.conf

I get no output. If I run

/opt/logrotate/bin/logrotate -v /opt/logrotate/etc/logrotate.conf

I get the following output:

reading config file /opt/logrotate/etc/logrotate.conf
reading config info for /var/adm/wtmp
reading config info for /var/adm/syslog/syslog.log
reading config info for /var/adm/syslog/mail.log
Handling 3 logs
rotating pattern: /var/adm/wtmp monthly (1 rotations)
empty log files are rotated old logs are removed
errors will be mailed to miguel.rentes@efacec.pt
rotating pattern: /var/adm/syslog/syslog.log after 1 days (10 rotations)
empty log files are rotated old logs are removed
errors will be mailed to miguel.rentes@efacec.pt
rotating pattern: /var/adm/syslog/mail.log weekly (5 rotations)
empty log files are rotated old logs are removed

Best regards,

Miguel Rentes
Dennis Handly
Acclaimed Contributor

Re: Logrotate is failing

>I get no output.

But did it do what it was suppose to do to the logfiles?
Miguel Silva Rentes
Regular Advisor

Re: Logrotate is failing

Nope.

This is what I have in /var/adm/syslog:

ls -al
total 18208
dr-xr-xr-x 2 bin bin 8192 Jul 13 09:00 .
drwxr-xr-x 15 adm adm 8192 Jul 5 16:31 ..
-rw-r----- 1 root root 85707 Jul 5 08:45 OLDsyslog.log
-r--r--r-- 1 root root 7271 Jul 13 11:03 mail.log
-r--r--r-- 1 root root 118835 Jul 13 08:32 mail.log.1
-rw-r----- 1 root root 82 Jul 13 10:14 syslog.log
-rw-r----- 1 root root 39 Jul 12 09:00 syslog.log.1
-rw-r----- 1 root root 9057037 Jul 7 14:44 xferlog

In this folder there should be compressed files and 3 syslog.log files because I started using logrotate last Friday and I'm telling logrotate to rotate in daily basis. What can be wrong?

Best regards,

Miguel Rentes
Miguel Silva Rentes
Regular Advisor

Re: Logrotate is failing

Hi Dennis,

I've checked my e-mail ang received this message:

"
Subject: errors rotating logs
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

sh: gzip: not found.
errors occured while rotating /var/adm/syslog/syslog.log

failed to compress log /var/adm/syslog/syslog.log.1
"

This points out that cron doesn't know where gzip is (which is in /usr/contrib/bin). I've changed my crontab to include this line at the top of /var/spool/cron/crontabs/root:

"PATH=/sbin:/usr/sbin:/usr/bin:/usr/contrib/bin:/usr/local/bin"

but when I stopped and started cron I got in my mail this message:

"
Your crontab file has an error in it.
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/contrib/bin:/usr/local/bin
unexpected symbol found
This entry has been ignored.

"

So, can anyone tell me how to configure cron to have the path to gzip in PATH?

Best regards,

Miguel Rentes
Dennis Handly
Acclaimed Contributor
Solution

Re: Logrotate is failing

>sh: gzip: not found.

I'm glad that failed as expected. :-)

>I've changed my crontab to include this line at the top of /var/spool/cron/crontabs/root:
>how to configure cron to have the path to gzip in PATH?

Ack!
You change your command part of the entry:
(All one long line.)
00 9 * * * PATH=/sbin:/usr/sbin:/usr/bin:/usr/contrib/bin:/usr/local/bin /opt/logrotate/bin/logrotate /opt/logrotate/etc/logrotate.conf
Steven E. Protter
Exalted Contributor

Re: Logrotate is failing

Shalom,

cron for Linux has a default PATH

Not so in HP-UX

Two choices:
1) set the PATH statement, preferably very early in your script.
2) Use full path for commands.

The second method is a problem if OS updates relocate the binaries and you don't wish to spend a lot of time porting your scripts.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Dennis Handly
Acclaimed Contributor

Re: Logrotate is failing

>SEP: cron for Linux has a default PATH. Not so in HP-UX

crontab(1) has a stripped down default path: PATH=/usr/bin:/usr/sbin:.
Miguel Silva Rentes
Regular Advisor

Re: Logrotate is failing

Hi Dennis,

Putting the PATH environment variable did solve my problem! I now have a working logrotate that rotates and compress my logs.

Thank you very much!

Best regards,

Miguel Rentes