FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » executing command with shell_exec()
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
executing command with shell_exec() [message #169363] Wed, 08 September 2010 16:06 Go to next message
cerr is currently offline  cerr
Messages: 33
Registered: September 2010
Karma: 0
Member
Hi There,

I execute a script in my php script with shell_exec():
$cmd = SCRIPT_PATH."PingGPSsource.py ".$_SESSION['prgIP']." ".
$_SESSION['AVLIP'];
logOutput("cmd:".$cmd);
$avlRet=shell_exec($cmd);
logOutput("result:".$avlRet);

Now if i execute the $cmd in a normal shell, it works with no problem
but when i execute it through my php script, $avlRet stays empty. Why
is that and how can I fix this?
Thanks for help and suggestions!

Ron
Re: executing command with shell_exec() [message #169365 is a reply to message #169363] Wed, 08 September 2010 16:21 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 9/8/2010 12:06 PM, cerr wrote:
> Hi There,
>
> I execute a script in my php script with shell_exec():
> $cmd = SCRIPT_PATH."PingGPSsource.py ".$_SESSION['prgIP']." ".
> $_SESSION['AVLIP'];
> logOutput("cmd:".$cmd);
> $avlRet=shell_exec($cmd);
> logOutput("result:".$avlRet);
>
> Now if i execute the $cmd in a normal shell, it works with no problem
> but when i execute it through my php script, $avlRet stays empty. Why
> is that and how can I fix this?
> Thanks for help and suggestions!
>
> Ron

First thing I would want to know is what is in SCRIPT_PATH? When you
say you execute it from your php script - do you mean running under the
web server? If so, does the web server have access to the script and
permission to execute it? The web server will almost always have
different permissions than the CLI user.

Are you sure the script is actually not executing, or could it be
executing but not producing any output?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: executing command with shell_exec() [message #169366 is a reply to message #169365] Wed, 08 September 2010 16:38 Go to previous messageGo to next message
jodleren is currently offline  jodleren
Messages: 7
Registered: September 2010
Karma: 0
Junior Member
On Sep 8, 7:21 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 9/8/2010 12:06 PM, cerr wrote:
>
>> Hi There,
>
>> I execute a script in my php script with shell_exec():
>>         $cmd = SCRIPT_PATH."PingGPSsource.py ".$_SESSION['prgIP']." ".
>> $_SESSION['AVLIP'];
>>         logOutput("cmd:".$cmd);
>>         $avlRet=shell_exec($cmd);
>>         logOutput("result:".$avlRet);
>
>> Now if i execute the $cmd in a normal shell, it works with no problem
>> but when i execute it through my php script, $avlRet stays empty. Why
>> is that and how can I fix this?
>> Thanks for help and suggestions!
>
>> Ron
>
> First thing I would want to know is what is in SCRIPT_PATH?  When you
> say you execute it from your php script - do you mean running under the
> web server?  If so, does the web server have access to the script and
> permission to execute it?  The web server will almost always have
> different permissions than the CLI user.
>
> Are you sure the script is actually not executing, or could it be
> executing but not producing any output?
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================

It works, we just now realised the problems with filename with 2 dots.

Btw the problem is the same with file:// - so the problem is probably
on the client side, I wonder if there is anything to do about it...

Sonnich
Re: executing command with shell_exec() [message #169367 is a reply to message #169366] Wed, 08 September 2010 16:41 Go to previous messageGo to next message
cerr is currently offline  cerr
Messages: 33
Registered: September 2010
Karma: 0
Member
On Sep 8, 9:38 am, jodleren <sonn...@hot.ee> wrote:
> On Sep 8, 7:21 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>
>
>
>
>
>> On 9/8/2010 12:06 PM, cerr wrote:
>
>>> Hi There,
>
>>> I execute a script in my php script with shell_exec():
>>>         $cmd = SCRIPT_PATH."PingGPSsource.py ".$_SESSION['prgIP']." ".
>>> $_SESSION['AVLIP'];
>>>         logOutput("cmd:".$cmd);
>>>         $avlRet=shell_exec($cmd);
>>>         logOutput("result:".$avlRet);
>
>>> Now if i execute the $cmd in a normal shell, it works with no problem
>>> but when i execute it through my php script, $avlRet stays empty. Why
>>> is that and how can I fix this?
>>> Thanks for help and suggestions!
>
>>> Ron
>
>> First thing I would want to know is what is in SCRIPT_PATH?  When you
>> say you execute it from your php script - do you mean running under the
>> web server?  If so, does the web server have access to the script and
>> permission to execute it?  The web server will almost always have
>> different permissions than the CLI user.
>
>> Are you sure the script is actually not executing, or could it be
>> executing but not producing any output?
>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================
>
> It works, we just now realised the problems with filename with 2 dots.
>
> Btw the problem is the same with file:// - so the problem is probably
> on the client side, I wonder if there is anything to do about it...
>
> Sonnich

Ho Sonnich,

I'm not exactly sure what you mean by "the problems with filename with
2 dots"...my path isn't file:// but "/var/www/localhost/cgi-bin/
PingGPSsource.py 192.168.103.75 169.254.0.1"

Thanks for your help!
Ron
Re: executing command with shell_exec() [message #169368 is a reply to message #169365] Wed, 08 September 2010 16:51 Go to previous messageGo to next message
cerr is currently offline  cerr
Messages: 33
Registered: September 2010
Karma: 0
Member
On Sep 8, 9:21 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 9/8/2010 12:06 PM, cerr wrote:
>
>> Hi There,
>
>> I execute a script in my php script with shell_exec():
>>         $cmd = SCRIPT_PATH."PingGPSsource.py ".$_SESSION['prgIP']." ".
>> $_SESSION['AVLIP'];
>>         logOutput("cmd:".$cmd);
>>         $avlRet=shell_exec($cmd);
>>         logOutput("result:".$avlRet);
>
>> Now if i execute the $cmd in a normal shell, it works with no problem
>> but when i execute it through my php script, $avlRet stays empty. Why
>> is that and how can I fix this?
>> Thanks for help and suggestions!
>
>> Ron
>
> First thing I would want to know is what is in SCRIPT_PATH?  
Hi Jerry,

cmd looks like:
/var/www/localhost/cgi-bin/PingGPSsource.py 192.168.103.75 169.254.0.1

> When you
> say you execute it from your php script - do you mean running under the
> web server?  If so, does the web server have access to the script and
> permission to execute it?
Yes, it is set to be world executable, I chmod-ed it to 777

> Are you sure the script is actually not executing, or could it be
> executing but not producing any output?
Well it actually seems as if the script would run but as if php
wouldn't let it execute all the way. I put a print in the first line
and that is what i'm getting back but nothing else...
The python script executes a ping on the remote host and thus takes a
second to execute...
Re: executing command with shell_exec() [message #169369 is a reply to message #169363] Wed, 08 September 2010 17:34 Go to previous messageGo to next message
matt[1] is currently offline  matt[1]
Messages: 40
Registered: September 2010
Karma: 0
Member
On Sep 8, 12:06 pm, cerr <ron.egg...@gmail.com> wrote:
> Hi There,
>
> I execute a script in my php script with shell_exec():
>        $cmd = SCRIPT_PATH."PingGPSsource.py ".$_SESSION['prgIP']." ".
> $_SESSION['AVLIP'];
>        logOutput("cmd:".$cmd);
>        $avlRet=shell_exec($cmd);
>        logOutput("result:".$avlRet);
>
> Now if i execute the $cmd in a normal shell, it works with no problem
> but when i execute it through my php script, $avlRet stays empty. Why
> is that and how can I fix this?
> Thanks for help and suggestions!
>
> Ron

Does the Python script rely on any shell environment variables? Those
will be different between the different executions. This includes
$PATH, so if you're calling out to "ping", you may have to provide a
full path. It's hard to guess without knowing the internals of the py
script, but that would also be inappropriate for this group :)
Re: executing command with shell_exec() [message #169370 is a reply to message #169369] Wed, 08 September 2010 18:23 Go to previous messageGo to next message
cerr is currently offline  cerr
Messages: 33
Registered: September 2010
Karma: 0
Member
On Sep 8, 10:34 am, matt <matthew.leonha...@gmail.com> wrote:
> On Sep 8, 12:06 pm, cerr <ron.egg...@gmail.com> wrote:
>
>> Hi There,
>
>> I execute a script in my php script with shell_exec():
>>        $cmd = SCRIPT_PATH."PingGPSsource.py ".$_SESSION['prgIP']." ".
>> $_SESSION['AVLIP'];
>>        logOutput("cmd:".$cmd);
>>        $avlRet=shell_exec($cmd);
>>        logOutput("result:".$avlRet);
>
>> Now if i execute the $cmd in a normal shell, it works with no problem
>> but when i execute it through my php script, $avlRet stays empty. Why
>> is that and how can I fix this?
>> Thanks for help and suggestions!
>
>> Ron
>
> Does the Python script rely on any shell environment variables?  Those
> will be different between the different executions.  This includes
> $PATH, so if you're calling out to "ping", you may have to provide a
> full path.  It's hard to guess without knowing the internals of the py
> script, but that would also be inappropriate for this group :)

right! but I in fact do execute a ping after creating an ssh handle
but i don't believe the problem is there.
I included some debug prints into my script that get tthrough to php
until we're at a certain position, which is weird...
it's like this:

***script start***
[a few global variable definitions]
print "PingGPSsource.py - start"
[reading command line arguments]
print "PingGPSsource.py - Got arguments"
print "prgIP:"+prgIP
print "avlIP:"+avlIP
print "prgPass:"+prgPass
print "this is before the writelog() implementation"
[writelog() function implementation which is fairly small]
print "and this is after"

print "start script" - this is not printing anymore and the script
appears to be terminated!
That's weird. isn't it?
Any clues there? :o
Thanbks a lot! And I'm sorry if ppl tell want to redirect me to a
python group, i'm aware f the fact that this maybe a python issue but
the script seems to work well when executed from the shell directly...
Re: executing command with shell_exec() [message #169371 is a reply to message #169370] Wed, 08 September 2010 18:26 Go to previous message
cerr is currently offline  cerr
Messages: 33
Registered: September 2010
Karma: 0
Member
On Sep 8, 11:23 am, cerr <ron.egg...@gmail.com> wrote:
> On Sep 8, 10:34 am, matt <matthew.leonha...@gmail.com> wrote:
>
>
>
>
>
>> On Sep 8, 12:06 pm, cerr <ron.egg...@gmail.com> wrote:
>
>>> Hi There,
>
>>> I execute a script in my php script with shell_exec():
>>>        $cmd = SCRIPT_PATH."PingGPSsource.py ".$_SESSION['prgIP']." ".
>>> $_SESSION['AVLIP'];
>>>        logOutput("cmd:".$cmd);
>>>        $avlRet=shell_exec($cmd);
>>>        logOutput("result:".$avlRet);
>
>>> Now if i execute the $cmd in a normal shell, it works with no problem
>>> but when i execute it through my php script, $avlRet stays empty. Why
>>> is that and how can I fix this?
>>> Thanks for help and suggestions!
>
>>> Ron
>
>> Does the Python script rely on any shell environment variables?  Those
>> will be different between the different executions.  This includes
>> $PATH, so if you're calling out to "ping", you may have to provide a
>> full path.  It's hard to guess without knowing the internals of the py
>> script, but that would also be inappropriate for this group :)
>
> right! but I in fact do execute a ping after creating an ssh handle
> but i don't believe the problem is there.
> I included some debug prints into my script that get tthrough to php
> until we're at a certain position, which is weird...
> it's like this:
>
> ***script start***
>  [a few global variable definitions]
> print "PingGPSsource.py - start"
>  [reading command line arguments]
> print "PingGPSsource.py - Got arguments"
> print "prgIP:"+prgIP
> print "avlIP:"+avlIP
> print "prgPass:"+prgPass
> print "this is before the writelog() implementation"
>  [writelog() function implementation which is fairly small]
> print "and this is after"
>
> print "start script" - this is not printing anymore and the script
> appears to be terminated!
> That's weird. isn't it?
> Any clues there? :o
> Thanbks a lot! And I'm sorry if ppl tell want to redirect me to a
> python group, i'm aware f the fact that this maybe a python issue but
> the script seems to work well when executed from the shell directly...

Okay, I just figured it out! The writelog() function which writes to a
logfile which wasn't accessible by user "apache" terminated the
script! Sorry to have used your time but thanks for the hints &
suggestions!!!

Ron
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Php variables to an email.
Next Topic: Re: Another heredoc question
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 23:20:12 GMT 2024

Total time taken to generate the page: 0.02794 seconds