Error by archive.sh call: ./archive.sh: 32: Bad substitution

I’m getting an error when running archive.sh:

sysadmin@mypiwikmachine:/var/www/piwik/misc/cron$ sh ./archive.sh
./archive.sh: 32: Bad substitution

$CMD_TOKEN_AUTH_RESULT has a value like: s:32:“22222aaaaaa777777b34bbbbbb387cce”;

I’m pretty sure the choke point is at the following line:
TOKEN_AUTH=${CMD_TOKEN_AUTH_RESULT:6:32}

The machine has been upgraded from 0.2.32 to 0.4.1; everything else seems to be working.
Does anybody have a clue?

I’m guessing your shell doesn’t support substringing.

Can you add “&serialize=0” to the query before that line?

And change that line to simply:

TOKEN_AUTH=${CMD_TOKEN_AUTH_RESULT}

[quote=vipsoft @ Jun 30 2009, 02:21 PM]I’m guessing your shell doesn’t support substringing.

Can you add “&serialize=0” to the query before that line?

And change that line to simply:

TOKEN_AUTH=${CMD_TOKEN_AUTH_RESULT}[/quote]

I also had this issue. The above fix seemed to resolve the Bad Substitution problem however, I am now running into a php error in index.php when I try to run archive.sh . Here is the error:

session_start() [function.session-start]: The session id contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' 
in '/var/www/piwik/index.php' at the line 50

any ideas?

What Piwik version are you running, alex?

In index.php, we have:

if(strlen(session_id()) === 0)
{
    session_start();
}

So, the session ID should be empty when we call session_start. What do you have in your php.ini for ‘session.auto_start’ and ‘session.use_trans_sid’?

I am using the latest version so 0.4.1 . The index.php file does match the code above. Here are the two lines you requested from my php.ini file.

session.auto_start = 0
session.use_trans_sid = 0

Hmmm. Not sure where the session id is coming from…

The session_id() is returning empty string… which is what it should be, correct? Since there is now new session yet. Manually setting the session id seems to resolve the issue:

if(strlen(session_id()) === 0)
{
        session_id("0");
        session_start();
}

However, this is not ideal.

[quote=vipsoft @ Jun 30 2009, 02:21 PM]I’m guessing your shell doesn’t support substringing.

Can you add “&serialize=0” to the query before that line?

And change that line to simply:

TOKEN_AUTH=${CMD_TOKEN_AUTH_RESULT}[/quote]

Thanks for your help (everybody). I have taken some lines of that script and tested them on several servers, all bash. The outcomes are not the same on all machines, I cannot explain this yet… so we go on testing!

Thanks for the serialize tip!

We’ve switched to using Zend_Session throughout in the upcoming 0.4.2 release. One of the changes removed the session_start() from index.php, so this may be moot.