7

I'm trying to run a shell script from a php frontend

heres the shell file (run.sh chmod to 777)

#!/bin/bash
wget -O index.html http://markets.usatoday.com/custom/usatoday-com/html-mktscreener.asp
python hw7-9.py index.html 
echo "done";

Heres the php front end

<?php
   $output = shell_exec("run.sh");
   echo "<pre>$output</pre>";
?>

But it php page doesn't return anything except

<pre></pre>
1
  • 1
    Add 2>&1 to the end of your shell command, i.e: "run.sh 2>&1". This will redirect any errors to standard output so you can debug further. Commented Dec 7, 2011 at 18:17

3 Answers 3

1

Have you tried doing error_reporting(-1); at the top of your PHP script. Likely shell_exec is disabled on your server.

Sign up to request clarification or add additional context in comments.

1 Comment

doing shell_exec("ls") works fine. Just some things like python file.py or run.sh dont work and I can't figure out why
1

Would you try $output = shell_exec("sh run.sh");

5 Comments

this outputs done but the file isn't downloaded and python isn't called (wget doesnt seem to run). Could it be that its running in a different directory?
Have you checked the directory permission of the directory you are running the script?
Yeah I set all files to 777 and the directory to the same
First run the shell script by sh run.sh in the bash shell. she if it works. and provided php script and the script are on the same directory, there is no reason, ur code shouldn't work.
I tested it, and it works fine. I'm in an afs system so it limits some things but the sys admin said that shell_exec was unblocked.
0

Check what user the php/web server is actually run as - e.g. "www-user" may have no permissions whatsoever to do the things your script is trying to do (and for good reason).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.