LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Running a .sh file via PHP (https://www.linuxquestions.org/questions/linux-newbie-8/running-a-sh-file-via-php-877234/)

Shnooter 04-26-2011 03:11 PM

Running a .sh file via PHP
 
I'm trying to run a .sh file from a PHP script. It needs to run in a screen as well as it runs a java file which needs to keep running until it's killed.

The following code works although if I try putting the path to the .sh file in then it doesn't appear to run.

Code:

$output = shell_exec('ps aux | grep http');
echo "<pre>$output</pre>";

Anyone got any ideas? I'm just experimenting at the moment

EDIT:
I've got it working with <?php shell_exec('sh /path/to/file.sh >/dev/null &' ); ?> which I had tried before... and then I remembered that the specific .sh I was trying didn't work correctly, oh well only a few hours of my life lost!

corp769 04-26-2011 06:36 PM

To rule out the simple things, have you made sure that your sh file is correctly chmod'd to execute? Also, you might have to run a direct command to run the sh file, like so:
Code:

sh file.sh
Kind regards,

Josh

Edit - I didn't see your edit.... my fault for not reading too thoroughly :D
As a note though, you could also use "bash" instead of sh, if the file contains strictly bash code, or zsh, etc...


All times are GMT -5. The time now is 04:49 PM.