When using logrotate from a cronjob, I am getting this erros:
error: unable to open /var/log/mylog.1 for compression
Does any one know what does it mean and how can I fix it ?
You're going to need to get more information.
Does the file exist, and does the user running cron have permission to read it?:
ls -l /var/log/mylog.1
See if logrotate can give more information. It should have a verbose flag you can turn on with '-v'.
It means that /var/log/mylog.1 does not exist or the permissions/ownership do not allow that file to be compressed. Check the permissions/ownership with ls -l /var/log/mylog*.
If the file exists, and the permissions are ok, then a cause can be that the file is open when you try to compress it. In order to avoid that, you can add the following line to your /etc/logrotate.conf:
delaycompress
I just hit this error myself. Summary: it was a conflict between logrotate and a postrotate script I'd written, where in certain circumstances my logrotate script would delete the just-moved log file before it was compressed. Although you'd think that logrotate would compress the file and then run the post-rotate script, it actually does it in the other order. Hence this error message.
Since logrotate directly manages the file that the question shows as missing, I can't think of anything else that might cause this problem, unless there's something really strange about the file permissions (e.g. writeable and not readable).