LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Very basic PHP (https://www.linuxquestions.org/questions/programming-9/very-basic-php-561765/)

ErrorBound 06-14-2007 07:54 AM

Very basic PHP
 
Hi,

I'm interested in making a very basic PHP script for a Linux server. It should only do this:
1. execute some command-line program (which normally prints some text to the screen)
2. Write this text to the web page instead.

This is for monitoring a cluster, and I'd like to be able to view the cluster status using a web browser instead of logging in by SSH or something.

Many thanks,

Guttorm 06-14-2007 08:05 AM

Hi

Something like:

PHP Code:

<?php
header
("Content-Type: text/plain");
system("ls");
?>

Of course, change the "ls" into a more useful command.

nc3b 06-14-2007 08:07 AM

Hello.

http://www.php.net/manual/en/function.system.php
http://www.php.net/manual/en/function.passthru.php
http://www.php.net/manual/en/function.popen.php

Please also have a look at
http://www.php.net/manual/en/functio...peshellcmd.php

Good luck.

ErrorBound 06-14-2007 09:32 AM

Ahh thank you, this is exactly what I was looking for. This works with commands like 'ls' and 'ps', but it does not print any output from the program I'd like to use. In this case the return value from system() is 1. Is this a permissions issue? I've tried chmod 777 on the program but this does not seem to make a difference.

senyahnoj 06-14-2007 09:43 AM

What program are you trying to use?

ErrorBound 06-14-2007 09:46 AM

Quote:

Originally Posted by senyahnoj
What program are you trying to use?

It's called condor_status from the Condor project (http://www.cs.wisc.edu/condor/). I'm not sure if this is relevant though? I can run the program as a normal unpriveledged user and it works, and I can also redirect the text output to a file (using the > operator) but this does not seem to work either when I try with PHP.

ErrorBound 06-14-2007 09:52 AM

I have a workaround....If I write a script which does nothing except run condor_status, and use PHP to execute the script, it works. I can't explain why. But I'll be happy with that.


All times are GMT -5. The time now is 05:44 AM.