Page 1 of 1

Error on running exec command

Posted: Mon Jun 11, 2007 5:34 am
by Kadanis
I hope this is the right forum, as this is a little bit php and a little bit Linux command line stuff

I am running the exec function to run a command on the box, which returns the current Exim queue size.

Code: Select all

$queue_size = exec('exim -bpc');
If I run this line of php via the command line, and echo the variable I get the results I'm looking for. However, when I run the same php page via a CRON job, instead of using the var in the code it emails me the following error

sh: exim: command not found.

Does anyone know what this means.? I understand something can't find the exim command, but I don't know what as this works perfectly from the command line.

Thanks in advance

Posted: Mon Jun 11, 2007 6:42 am
by volka
There's an environment variable PATH that controls where the shell is looking for executables.
This variable can change from account to account. The webserver probably uses another account than you do when you're logged in.

You can compare the PATH settings with

Code: Select all

echo $PATH

Code: Select all

<?php echo 'path: ', $_ENV['PATH']; ?>
You can also let the shell (or a helper application) tell you which exim it invokes

Code: Select all

which exim

Posted: Mon Jun 11, 2007 6:43 am
by Kadanis
solved this, thought i'd post in case it helps anyone else.

php can't run commands without a full path to the binary (or at least thats what it took to fix this)

Code: Select all

echo exec('/usr/sbin/exim -bpc');
will return the right info.