Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-26-2011, 04:11 PM   #1
Registered: Sep 2005
Posts: 30

Rep: Reputation: 15
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.

$output = shell_exec('ps aux | grep http');
echo "<pre>$output</pre>";
Anyone got any ideas? I'm just experimenting at the moment

I've got it working with <?php shell_exec('sh /path/to/ >/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!

Last edited by Shnooter; 04-26-2011 at 04:25 PM.
Old 04-26-2011, 07:36 PM   #2
LQ Guru
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
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:
Kind regards,


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

Last edited by corp769; 04-26-2011 at 07:38 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache downloads php file instead of running script cov Linux - Server 4 05-13-2010 05:33 PM
running file from root and running file from user kedar Linux - Newbie 2 09-16-2008 02:59 AM
Centos 5.2 running Apache 2 and PHP 4 cannot display info.php codenjanod Linux - Server 2 08-19-2008 03:00 AM
Running php file from shell? jchambers Programming 5 02-28-2008 06:56 PM
How to get php 4.4.2 and php 5.1.4 running on fedora core 5? markg85 Linux - Software 2 06-18-2006 10:23 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:52 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration