 |
 |
Shell Command from Web Page?
|
 |
|
 |
|
Dedicated MacNNer
Join Date: May 2002
Location: Brooklyn, NY
Status:
Offline
|
|
Hi,
I was wondering if there's a way to run a shell command from a web page, and print its output to that web page? It seems like PHP should be able to do this sort of thing? For instance, how would I get a web page to display the entire output from "uptime" ?
Thanks!
gabe
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Feb 2001
Location: Manhattan
Status:
Offline
|
|
Originally posted by Zimwy:
Hi,
I was wondering if there's a way to run a shell command from a web page, and print its output to that web page? It seems like PHP should be able to do this sort of thing? For instance, how would I get a web page to display the entire output from "uptime" ?
Thanks!
gabe
not having done this in a while, i believe you would do this:
[PHP]
echo `uptime`;
[/PHP]
...anyways, check out the reference pages at www.php.net for backtick usage.
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Mar 2003
Status:
Offline
|
|
just create a simple cgi-script.
-- cut here
#!/bin/sh
echo "Content-type: text/plain\n\n"
uptime
-- cut here
just put it on your cgi-bin directory, add the right permissions, and thats it..
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: May 2002
Location: Brooklyn, NY
Status:
Offline
|
|
Hey, the backtick thing works great, almost... Okay, I'm a bit stumped by this. If I do:
[PHP]
echo `lsof`;
[/PHP]
It works fine, but if I do:
[PHP]
echo `lsof | awk '/mp3/'`;
[/PHP]
THen I get nothing. The thing is that the second command works perfectly fine in the terminal. I've tried giving full path names to lsof and awk, no luck there. lsof alone works fine. I'm stumped. Any ideas? Other commands, such as uptime work fine as well. Help!
Gabe
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Feb 2001
Location: Manhattan
Status:
Offline
|
|
Originally posted by Zimwy:
Hey, the backtick thing works great, almost... Okay, I'm a bit stumped by this. If I do:
[PHP]
echo `lsof`;
[/PHP]
It works fine, but if I do:
[PHP]
echo `lsof | awk '/mp3/'`;
[/PHP]
THen I get nothing. The thing is that the second command works perfectly fine in the terminal. I've tried giving full path names to lsof and awk, no luck there. lsof alone works fine. I'm stumped. Any ideas? Other commands, such as uptime work fine as well. Help!
Gabe
...hmm, beats me why you can't pipe stuff, but why don't you just use php's regular expressions to handle it. assign the backtick output to a variable and then run select what you need...
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: May 2002
Location: Brooklyn, NY
Status:
Offline
|
|
I'll definitely look into select. I've searched the PHP page for it, and I can't find it. Do you have any hints of where to get started for doing awk and grep-like things within php? Thanks. With the pipe, thing is that it does work. I do it to get uptime into a more readable format by piping it to awk. It just won't work with lsof. I can't pipe lsof to grep, or awk, or anything. Very confusing...
gabe
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Feb 2001
Location: Manhattan
Status:
Offline
|
|
Originally posted by Zimwy:
I'll definitely look into select. I've searched the PHP page for it, and I can't find it. Do you have any hints of where to get started for doing awk and grep-like things within php? Thanks. With the pipe, thing is that it does work. I do it to get uptime into a more readable format by piping it to awk. It just won't work with lsof. I can't pipe lsof to grep, or awk, or anything. Very confusing...
gabe
...i didn't mean run the "select" function. i meant run a regular expression to "select" what you want. sorry for the misunderstanding...
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status:
Offline
|
|
Have you tried it with the exec command? A lot of contributors have noted that the backtick method sends your commands through a shell, whilst exec calls your commands directly.
|
|
Computer thez nohhh...
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: May 2002
Location: Brooklyn, NY
Status:
Offline
|
|
Hey,
No dice there either.
Thanks though
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Mar 2003
Status:
Offline
|
|
Originally posted by Simon Mundy:
Have you tried it with the exec command? A lot of contributors have noted that the backtick method sends your commands through a shell, whilst exec calls your commands directly.
err..
the only difference its that exec does not spawn a new shell to run the command.
so in this case there its no difference..
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|