IanGP
asked on
PHP exec()
Hi There,
I am new to PHP so this might seem like a very basic problem to resolve...
I have created ledson.sh that I want to execute from a php page then once the .sh has run, the user must be directed to another page:
./ledson.sh works fine
If I comment out the redirect line, and print $retval, I get a result but script doesn't run.
Where am I going wrong?
Thanks in advance.
Ian
I am new to PHP so this might seem like a very basic problem to resolve...
I have created ledson.sh that I want to execute from a php page then once the .sh has run, the user must be directed to another page:
<?php
exec('ledson.sh',$retval);
header('Location: http://url.url/leds.php');
?>
./ledson.sh works fine
If I comment out the redirect line, and print $retval, I get a result but script doesn't run.
Where am I going wrong?
Thanks in advance.
Ian
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Afterthought, but hopefully a useful one. Here is a book that can help you get a foundation in how PHP and MySQL (or MySQLi) work together. Very much worth the investment of a month of your time to study it! It has great explanations and examples and it comes with a downloadable code library that you can copy and modify for your own use. Now in its fifth printing, it has been a permanent part of my professional library since Edition One.
http://www.sitepoint.com/books/phpmysql5/
best regards, ~Ray
http://www.sitepoint.com/books/phpmysql5/
best regards, ~Ray
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
greetings IanGP, , u may have considered this already, but u said u were new to PHP, - Many php security settings have any OS calls like -
exec( )
shell_exec( )
Disabled, and may not even issue a warning, or exception if they are called,
usually if you look at the -
phpinfo();
u can see any and all of the disabled commands and options, or ask your server support people.
exec( )
shell_exec( )
Disabled, and may not even issue a warning, or exception if they are called,
usually if you look at the -
phpinfo();
u can see any and all of the disabled commands and options, or ask your server support people.
ASKER
Thanks, I'll try the suggestions and let you all know.
Regards
Ian
Regards
Ian
ASKER
OK....
@fosiul01 - ledson.sh is owned by www-data and I've done chmod 775 ledson.sh and I can run it (and ledsoff.sh).
@Ray. I'm working on a Raspberry Pi, playing with the GPIO's
ledson.sh is a little script to switch on LEDs & Thanks, purchased the ebook.....
@slick812 - tried adding disable_functions = "" to php.ini and commented out the line altogether
@insoftservice and Ray - I have no parameters required for ledson.sh. really just want to toggle on and off.
Thanks
Ian
@fosiul01 - ledson.sh is owned by www-data and I've done chmod 775 ledson.sh and I can run it (and ledsoff.sh).
@Ray. I'm working on a Raspberry Pi, playing with the GPIO's
ledson.sh is a little script to switch on LEDs & Thanks, purchased the ebook.....
@slick812 - tried adding disable_functions = "" to php.ini and commented out the line altogether
@insoftservice and Ray - I have no parameters required for ledson.sh. really just want to toggle on and off.
Thanks
Ian
ASKER
Hi,
Still battling with this....
But for the interim I'll use file_put-contents It at least lets me control the output file.
Cheers.
Ian
Still battling with this....
But for the interim I'll use file_put-contents It at least lets me control the output file.
Cheers.
Ian
OK, not sure this will help, but linux can have a "what to call to do the job" setting problem, I ran into this BIG TIME when trying to call anything from system in CRON timed run of PHP scripts, sometimes to get the CRON to run PHP, you have to precede the cron call with PHP, so the PHP engine will process and run the PHP script, I remember having to precede a shell script call (work.sh) with the BASH, so the linux now working in PHP mode, would run that script in the shell script engine, , sorry I can not be more specific to your problem, but I am not a Linux command knowledge guy, and I got help in order to get those CRON php runs to work. You may also need to do a full path to the BASH engine, or not?
Have you tried to run any non shell script, linux executables like whois, from exec or shell_exec call from php, did they work?
Have you tried to run any non shell script, linux executables like whois, from exec or shell_exec call from php, did they work?
hi did u tried with my comments and later tried to do shell script.
If i am not wrong ur shell script was not working proper right in php ?
please elaborate little more.
ini_set('display_errors',' on');
and let us know the issue , does redirection work properly
header('Location: http://url.url/leds.php');exit;
If i am not wrong ur shell script was not working proper right in php ?
please elaborate little more.
ini_set('display_errors','
and let us know the issue , does redirection work properly
header('Location: http://url.url/leds.php');exit;
ASKER
Thanks All.
Although I haven't fully gotten to the bottom of the problem, your insights got me in the right direction.
Thanks
Ian
Although I haven't fully gotten to the bottom of the problem, your insights got me in the right direction.
Thanks
Ian
If ledson.sh takes a while to run, your PHP script might need to sleep() for a while or otherwise synchronize itself with the other script.
http://us3.php.net/manual/en/function.sleep.php