LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-27-2008, 09:21 AM   #1
Sambojambo
LQ Newbie
 
Registered: Feb 2008
Location: UK
Distribution: Ubuntu - Hardy Heron
Posts: 10

Rep: Reputation: 0
apache php - executing commands using system(), problems


I sure that there's going to be a quick answer to this. I'm calling a command through the system() function in php.

PHP Code:
$cmd 'tide -ml -fh -o $output ';
system($cmd); 
When I run the script through www-data it won't execute. I've checked the permissions on the bin and it looks fine. I'm confused as www-data can execute other bins in the same folder with the same permissions. This is on a standard install of Ubuntu Hardy.

Code:
sam@nugget:/$ ls -la /usr/bin/tide | grep tide
-rwxr-xr-x 1 root root 370852 2008-04-03 21:53 /usr/bin/tide
I'm not the most experienced system admin - I must be missing something obvious?

Thanks in advance for any help
 
Old 05-27-2008, 11:32 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
One thing is wrong dor sure: When using single quotes (' '), as you did, the variable $output will not be replaced with the value of $output. Use double quotes (" ") instead.

Also, what is the value of $output? Can www-data really write there?
You can Check with this: $cmd = "tide -ml -fh -o $output 2>&1"; Any errors from the 'tide' program will show in you browser.

I noticed 'tide' outputs html code. You could also try without the -o $output part first. The html from 'tide' will show nicely in the browser.

Complete example:
PHP Code:
<html>
    <head>
        <title>Tides</title>
    </head>
    <body>
        <?php
            $output 
'/tmp/tide.html';
            
$cmd "tide -ml -fh";
            
// $cmd = "tide -ml -fh -o $output 2>&1";
            // $cmd = "tide -ml -fh -o $output";
            
system($cmd);
        
?>
    </body>
</html>

Last edited by Hko; 05-27-2008 at 11:37 AM.
 
Old 05-28-2008, 05:19 AM   #3
Sambojambo
LQ Newbie
 
Registered: Feb 2008
Location: UK
Distribution: Ubuntu - Hardy Heron
Posts: 10

Original Poster
Rep: Reputation: 0
Late night silly mistake...

Thanks for your reply Hko - and your simple script help pin down my silly mistake quickly. Apache was unable to write to the $output file which I was soon able to see with '2>&1'. The single/double quote issue was just a typo in the post.

Thanks again
 
Old 05-29-2008, 11:52 AM   #4
seraphim172
Member
 
Registered: May 2008
Posts: 101

Rep: Reputation: 15
Just a note in general: If you run any system commands in PHP be prepared for time-out problems if the operations takes long to finish. Fore example, calling ghostscript to merge a set of PDF files can take longer than the web server allows the PHP process to run. This is often a problem with osCommerce modules.

Linux Archive

Last edited by seraphim172; 06-25-2008 at 04:42 AM.
 
  


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
executing shell commands in PHP mohtasham1983 Programming 7 09-14-2007 11:04 AM
Executing system commands in a php script atiq Linux - Server 2 02-26-2007 09:45 AM
Executing shell commands through PHP!!! Richtown Linux - Newbie 6 04-12-2006 02:57 PM
PHP executing System command abdul_zu Linux - General 4 12-28-2005 02:14 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:21 PM.

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