Piwik cron job not updating interface

Hello there,

I am experiencing problems with running the Piwik cron job.
If I run archive.sh via SSH, everything works fine and I get the following output:


Starting Piwik reports archiving...


Archiving period = day for idsite = 1...
<?xml version="1.0" encoding="utf-8" ?>
<results>
	<result date="2011-08-10">8514</result>
	…
	<result date="2011-09-30">917</result>
</results>
Archiving period = week for idsite = 1...
<?xml version="1.0" encoding="utf-8" ?>
<results>
	<result date="2010-10-04 to 2010-10-10">6446</result>
	…
	<result date="2011-09-26 to 2011-10-02">10894</result>
</results>
Archiving period = month for idsite = 1...
<?xml version="1.0" encoding="utf-8" ?>
<results>
	<result date="2007-06" />
	…
	<result date="2011-09">90591</result>
</results>
Archiving period = year for idsite = 1...
<?xml version="1.0" encoding="utf-8" ?>
<results>
	<result date="2001" />
	…
	<result date="2011">467676</result>
</results>
Archiving for idsite = 1 done!

Reports archiving finished.
---------------------------
Starting Scheduled tasks...

task,output
Piwik_CoreAdminHome.optimizeArchiveTable,Time elapsed: 0.543s
Piwik_PrivacyManager.deleteLogTables,Time elapsed: 0.000s
Finished Scheduled tasks.

After that, I can see the updated data in the Piwik interface.

If I run archive.sh as cron job, the output looks very similar – except for “No data available” at the end.
It makes no difference if I call the cron job as root or as a privileged user.
The main problem is: If archive.sh is run as cron job, no new data is displayed in Piwik’s interface.


Archiving period = day for idsite = 1...
<?xml version="1.0" encoding="utf-8" ?>
<results>
	<result date="2011-08-09">9794</result>
	…
	<result date="2011-09-29">2370</result>
</results>
Archiving period = week for idsite = 1...
<?xml version="1.0" encoding="utf-8" ?>
<results>
	<result date="2010-10-04 to 2010-10-10">6446</result>
	…
	<result date="2011-09-26 to 2011-10-02">9966</result>
</results>
Archiving period = month for idsite = 1...
<?xml version="1.0" encoding="utf-8" ?>
<results>
	<result date="2007-06" />
	…
	<result date="2011-09">89663</result>
</results>
Archiving period = year for idsite = 1...
<?xml version="1.0" encoding="utf-8" ?>
<results>
	<result date="2001" />
	…
	<result date="2011">466748</result>
</results>
Archiving for idsite = 1 done!
Reports archiving finished.
---------------------------
Starting Scheduled tasks...

No data available
Finished Scheduled tasks.

Can you paste in what your cron job looks like?

It looks like this:

55 23   * * *   username      /path/to/piwik/misc/cron/archive.sh

Did you set a path? before the archive script? Also, good idea to do something like

/path/to/piwik/misc/cron/archive.sh > /path/to/piwik/misc/cron/archive.log

No, I didn’t set a path. Why would I have to do this? And what path?

the “> archive.log” wouldn’t do anything but write the output to archive.log instead of sending me an e-mail. I guess this won’t fix the problem :slight_smile:

Any ideas on how I could fix this?

Hello
wmnnd,

Have you tried configuring your environment variables like .bash_profile?
Maybe the crontab didn´t recognize the variable PHP_HOME or PHP_BIN.
You have to configure your .bash_profile like this:

PHP_HOME=/app/prd1bea/php5.3.8
PHP_BIN=/app/prd1bea/php5.3.8/bin/php

PATH=$PATH:$HOME/bin:$PHP_HOME/bin

export PHP_HOME
export PHP_BIN
export PATH

Or in your crontab put variable PATH into the crontab, like this:
PATH=/usr/lib64/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/prd1bea/bin:/app/prd1bea/php5.3.8/bin

Let me know if these solutions it´s worked for you.

The $PATH variable is already definded in my /etc/crontab. And I can’t see any PHP_HOME or PHP_BIN variables.

echo $PHP_BIN

gives me an empty result.

But now I have added an

echo $CMD

to archive.sh, so I’ll see whether the script can assemble the right command.

My apologies wmnnd, when I was talking about the path I was referring to what ramilani12 suggested to do.

In our archive.sh script we had to comment out the top lines and add the PHP_BIN path.


#for TEST_PHP_BIN in php5 php php-cli php-cgi; do
#  if which $TEST_PHP_BIN >/dev/null 2>/dev/null; then
#    PHP_BIN=`which $TEST_PHP_BIN`
#    break
#  fi
#done
#if test -z $PHP_BIN; then
#  echo "php binary not found. Make sure php5 or php exists in
#PATH." >&2
#  exit 1
#fi

PHP_BIN=/opt/lampp/bin/php


Though I believe if you had to do this you would have been given an error when trying to run the archive.sh.

We also had to enter:
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/opt/lampp/bin
in the crontab

My echo $CMD now shows that everything with the paths appears to be fine.

Here is what the script outputs as $CMD:

/usr/bin/php5 -q /www/piwik/misc/cron/../../index.php -- module=API&method=CoreAdminHome.runScheduledTasks&format=csv&convertToUnicode=0&token_auth=4bc46e2765fd9e76d4a69171c275559d

/www/piwik/ is where my piwik installation resides and /usr/bin/php5 is the correct path for PHP.

Here is the end of the script output:

</results>
Archiving for idsite = 8 done!
Reports archiving finished.
---------------------------
Starting Scheduled tasks...

task,output
Piwik_CoreAdminHome.optimizeArchiveTable,Time elapsed: 0.388s
Piwik_PrivacyManager.deleteLogTables,Time elapsed: 0.000s

Finished Scheduled tasks.

Im am desperate … why does the cronjob not work? What else could I check?

try to test running the CRON as the same user as will be ran when the cron executes.

For example:


time su www-data -c "/usr/bin/php5 /home/www/dev5.piwik.org/misc/cron/archive.sh" | less

Maybe you will find different output?

The command you posted doesn’t appear to be sensible … why would you pass archive.sh to php? This doesn’t do anything here.

But running

su -c my_user /path/archive.sh

works perfectly fine.

Yes running


Su -c "sh /path/to/archive.sh"

will work the same.

This is a shot in the dark but you could try adding


pathmunge /opt/lampp/bin after

in etc/profile – then set the path in your crontab

I don’t have that path :wink:

I guess I will have to file a bug report. Because in my view, a script which doesn’t work and shows no error message, has a bug :slight_smile:

Mh, the problem is still occurring with the current version 1.6.
Any new suggestions?