Cron archive + docker : do not work

Hello,

I’m using docker to run Matomo and I’ve set up a cron to get auto-archiving working.

Here is my crontab:

*/5 * * * * su www-data -s /bin/bash -c '/usr/local/bin/php /var/www/html/console core:archive --url=https://matomo.XXX .com/2>/tmp/matomo-archive-error.log >/tmp/matomo-archive.log'

The cron task is triggered every 5min, but the php command has no effect.
The files matomo-archive-error.log and matomo-archive.log are well created, but are empty (o byte).

The strangest thing is that if I manually run the following command from the container shell, it works perfectly fine :confused:

su www-data -s /bin/bash -c '/usr/local/bin/php /var/www/html/console core:archive --url=https://matomo.XXX.com/2>/tmp /matomo-archive-error.log >/tmp/matomo-archive.log'

If anyone has a good idea… :pray:

Thank you in advance for your help…

…when you are alone in the world!!! :sweat_smile:

So I found the solution that I share hoping it can help someone… :wink:

The problem was that the cron was not accessing the environment variables which are necessary for the execution of the command.

I solved the problem by adding the following statement in the Dockefile:

RUN printenv > /etc/environment
1 Like