Cronjob does not work

Hello, i have the problem that my cronjob looks like as if it has no data to process.
I am running the job (which i have created using your howto) with the user www-data. It looks like this:

MAILTO="meine@email.addi"
5 * * * * /export/vhosts/default/htdocs/piwik/misc/cron/archive.sh

I recieve mail with the following content:

Starting Piwik archiving...

If i run the script from the shell with root rights it looks like this:

piwik-dev:~# sh /export/vhosts/default/htdocs/piwik/misc/cron/archive.sh
Starting Piwik archiving...

Piwik archiving finished.
piwik-dev:~#

I created about 50000 page hits which are displayed correctly inside “LiveVisitors” and which are processed correctly when i process the data “browser side” and not inside a cronjob. The only thing i can imagine is that the cronjob has nothing to do, maybe because it only processes data which was generated min. 1 day ago.
The cronjob runs smooth and without any errors on my other machine, both with your actual piwik version 0.6.4.
I double checked user rights, all files and folders belong to the www-data user. Chmod rights are also set correctly.
Any ideas?

ok i made a slight progress, it seems that it is not possible to start a session, heres a part of the error log:

Archiving period = week for idsite = http-equiv="Content-Type"...
<html>
<head>
    <title>Piwik &rsaquo; Error</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="shortcut icon" href="plugins/CoreHome/templates/images/favicon.ico" />
    <link rel="stylesheet" type="text/css" href="themes/default/simple_structure.css" />
</head>
<body>
<div id="content">
    <div id="title"><span id="h1">Piwik </span><span id="subh1"> # open source web analytics</span></div>
    
<p>Unable to start session.  Check that session.save_path or tmp/sessions is writeable.</p> </div>
</body>
</html>

Whats weird is that that the tmp/sessions folder has 777 and is owned by www-data which is correct.
Also “session.save_path” is disabled inside php.ini. I tried to enable it but the error msg stays the same.

Whats also weird is that it says:

Archiving period = week for idsite = http-equiv="Content-Type"...

isnt it supposed to look like:

Archiving period = week for idsite = 1...

or something? Im confused…

edit:
ok, it seems that the script is unable to fetch the siteid. In line 66 of your archive.sh script it tests the result of CMD_GET_ID_SITES which should be 1 2 3 4 5 and so on.
I simply added a new line between the lines 66 and 67 so that it looks like this:

TEST_IS_NUMERIC=`echo $idsite | egrep '^[0-9]+$'`
echo "IS TEST NUMERIC: $TEST_IS_NUMERIC"
if [ "$TEST_IS_NUMERIC" ]

This should output 1, 2, 3 and so on. It works fine on my other mashine, the output there is:

Starting Piwik archiving...
Started at: Mon Jul 26 15:01:55 CEST 2010

IS TEST NUMERIC: 1

Archiving period = day for idsite = 1...
<?xml version="1.0" encoding="utf-8" ?>
<results>
    <result date="2010-06-05" />
    <result date="2010-06-06" />
    <result date="2010-06-07" />
...

On the other machine the output is:

piwik-dev:/export/vhosts/default/htdocs/piwik/misc/cron# sh archive.sh 
Starting Piwik archiving...

IS TEST NUMERIC: 
IS TEST NUMERIC: 
[...many more of these...]
IS TEST NUMERIC: 
IS TEST NUMERIC: 

Piwik archiving finished.

The output of $ID_SITES is:

<html> <head> <title>Piwik &rsaquo; Error</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="shortcut icon" href="plugins/CoreHome/templates/images/favicon.ico" /> <link rel="stylesheet" type="text/css" href="themes/default/simple_structure.css" /> </head> <body> <div id="content"> <div id="title"><span id="h1">Piwik </span><span id="subh1"> # open source web analytics</span></div> <p>Unable to start session. Check that session.save_path or tmp/sessions is writeable.</p> </div> </body> </html>

So i am back at the sessions problem, which is really annoying because the folders are writeable, the tmp/sessions folder is full of data. All the other pages are working properly, and they also use sessions, i dunno… style_emoticons/<#EMO_DIR#>/unsure.gif

Your cron job probably runs as a different user from your web server. You’ll have to change the permissions on the tmp/sessions folder so that your cron user can write to that directory.

The cronjob runs as user www-data and it does not make any difference if i run the file manually from console, as www-data or even as root. Everyone can write to the tmp/sessions folder and theres also no global sessions folder in php.ini set.
The tmp/sessions folder if full of files and i guess that i would run into big problems while using piwik inside the browser if it was not writeable. The stats can also be processed when i switch from cronjob back to browerside processing. Its just not possible to create a session when running from the script.
I dont think its because of some buggy coding inside the script because it runs correct on my private server, but its freaking me out that i cant figure out what the fuck is wrong.

www-data@piwik-dev:/export/vhosts/default/htdocs/piwik$ ls -al

total 56
drwxr-xr-x 12 www-data www-data 4096 2010-07-27 08:00 .
drwxr-xr-x  4 www-data www-data   65 2010-07-27 07:58 ..
drwxr-xr-x  2 www-data www-data   99 2010-07-27 08:01 config
drwxr-xr-x 17 www-data www-data 4096 2010-07-22 11:34 core
-rw-r--r--  1 www-data www-data    0 2010-07-27 08:00 favicon.ico
-rw-r--r--  1 www-data www-data 1546 2010-04-25 16:00 index.php
drwxr-xr-x  2 www-data www-data   50 2010-07-22 11:34 js
drwxr-xr-x  2 www-data www-data 4096 2010-07-22 11:34 lang
-rw-r--r--  1 www-data www-data 4460 2010-07-15 18:23 LEGALNOTICE
drwxr-xr-x 17 www-data www-data 4096 2010-07-22 11:34 libs
drwxr-xr-x  4 www-data www-data 4096 2010-07-22 11:34 misc
-rw-r--r--  1 www-data www-data 8388 2010-03-18 07:51 piwik.js
-rw-r--r--  1 www-data www-data 2375 2010-07-16 14:45 piwik.php
drwxr-xr-x 37 www-data www-data 4096 2010-07-22 11:34 plugins
-rw-r--r--  1 www-data www-data 1733 2010-07-01 23:06 README
-rw-r--r--  1 www-data www-data    0 2010-07-27 08:00 robots.txt
drwxr-xr-x  2 www-data www-data   23 2010-07-22 11:34 tests
drwxr-xr-x  3 www-data www-data   20 2010-07-22 11:34 themes
drwxrwxrwx  7 www-data www-data   77 2010-07-27 08:03 tmp

www-data@piwik-dev:/export/vhosts/default/htdocs/piwik$ cd tmp
www-data@piwik-dev:/export/vhosts/default/htdocs/piwik/tmp$ ls -al

total 704
drwxrwxrwx  8 www-data www-data     88 2010-07-26 13:36 .
drwxrwxrwx 12 www-data www-data   4096 2010-07-27 07:57 ..
drwxrwxrwx  2 www-data www-data     91 2010-07-26 08:09 assets
drwxrwxrwx  3 www-data www-data     20 2010-07-26 07:37 cache
drwxrwxrwx  2 www-data www-data      6 2010-07-26 07:36 latest
drwxrwxrwx  2 www-data www-data    107 2010-07-27 07:02 logs
drwxrwxrwx  2 www-data www-data 565248 2010-07-26 09:09 sessions
drwxrwxrwx  2 www-data www-data   4096 2010-07-26 10:13 templates_c

www-data@piwik-dev:/export/vhosts/default/htdocs/piwik/tmp$

I even tried to set the sessions save path globally inside the php.ini

session.save_path = /tmp/sessions

relogged into the piwik webinterface to check if it creates a new session inside the new directory, and it does. But still it wont create a session from the script.

PROBLEM SOLVED:

aptitude install php5-cli