LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 04-26-2011, 03:11 PM   #1
Shnooter
Member
 
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.

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!

Last edited by Shnooter; 04-26-2011 at 03:25 PM.
 
Old 04-26-2011, 06:36 PM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
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
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 06:38 PM.
 
  


Reply



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 04:33 PM
running file from root and running file from user kedar Linux - Newbie 2 09-16-2008 01:59 AM
Centos 5.2 running Apache 2 and PHP 4 cannot display info.php codenjanod Linux - Server 2 08-19-2008 02:00 AM
Running php file from shell? jchambers Programming 5 02-28-2008 05: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 09:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:09 AM.

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