I have a crontab the compress log files.
In crontab -e I have -I’m root-:
5 3 * * 6 find /toMyLogs -name "access*" -a ! -name '*.bz2' -ctime +7 -exec bzip2 -zv {} \;
35 3 * * 6 find /toMyLogs -name "error*" -a ! -name '*.bz2' -ctime +7 -exec bzip2 -zv {} \;
An example of the logs are:
$ ls -la /toMyLogs
-rw-r--r-- 1 root root 33317 Jul 2 19:04 error_1.log.2012-07-02
-rw-r--r-- 1 root root 12928 Jul 3 08:55 error_2.log.2012-07-03
If I execute the command by hand, this is:
find /toMyLogs -name "access*" -a ! -name '*.bz2' -ctime +7 -exec bzip2 -zv {} \;
it works, but in cron does not work. I did some mini-test with example files -not the logs- and ran cron. It worked. So, cron is definitively running.
Do you have any idea of whats is going on. Permissions or the time?
The environment is set up differently when you run cron. It is quite possible that the PATH used by cron does not find the bzip2 program.
Reasons why crontab does not work