Running a Unix shell script from PHP

Posted on 2006-04-20
Medium Priority
Last Modified: 2006-11-18
Hey, Experts...

I can't kick off a unix shell script from inside my PHP web page...can I?  

Question by:bakum
  • 2
  • 2
LVL 15

Expert Comment

ID: 16503640
You can, if your PHP is not in safe mode or restricted in a similar way by your web hosting provider. See http://us2.php.net/manual/en/ref.exec.php

Author Comment

ID: 16512044
I've upped the point value here because while those commands are useful...what I want to run is a ~script~.  And I can't seem to make the script run.  The command returns no output, return value is 1.  

It might bear upon the situation that the script makes an FTP connection and downloads any files that are in the remote directory.  Anyone think this is possible?  

Here is the PHP code I'm trying to execute...$output never returns anything:

$output = `sh myftpscript.sh >>logfile.txt`;
echo $output;

here is the myftpscript.sh...which works great when executed from the command line:


ftp -n ftp.XXXXXX.com<<END_SCRIPT
quote USER $USER
lcd releases
mget  *.*

exit 0

LVL 15

Accepted Solution

m1tk4 earned 2000 total points
ID: 16512205
$output will never get anything because you redirected all output to logfile txt. That is, if your sample runs anything at all - I'm not sure backticks (``) create an environment enough to find sh - try replacing it with /bin/sh myftpscript.sh.

Author Comment

ID: 16557624
Outstanding.  Once again, this is truly an "EXPERTS" exchange.  


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question