Home > Archive > PERL CGI Beginners > February 2005 > printing output of a command
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
printing output of a command
|
|
| TapasranjanMohapatra 2005-02-21, 3:55 am |
| All,
i am new to cgi. Please let me know why I dont get the data printed?
I have abc.cgi in /var/www/cgi-bin
When the $cmd is "ls" I get the filenames when I visit =
localhost/cgi-bin/abc.cgi
But when the $cmd is the snmpquerry, I get nothing on the page, though I =
get the desired output(value of sysContact.0) when I run the script in =
commandline.
----------------------------
#! /usr/bin/perl
print "Content-type: text/html\n\n";
print <<"END OF PRINT";
<html>
<head><title>test</title></head>
<body>
END OF PRINT
my $cmd =3D "snmpget 23.23.23.23 public sysContact.0";
#my $cmd =3D "ls";
my $res =3D qx!$cmd!;
chomp($res);
print <<"end of print";
<center>
$res
</center>
</body></html>
end of print
-------------------------------------
TIA
Tapas
| |
| Paul Archer 2005-02-21, 8:55 am |
| This is a very common problem. When you run the script from the command
line, you are running it with different privileges and a different path than
when the web server runs it.
Most likely, either the command is not in the path for CGI scripts (try
setting $ENV{PATH} or calling the command with the full pathname), or the
web server, which should run as 'nobody', doesn't have permission to run the
command properly.
10:29am, TapasranjanMohapatra wrote:
> All,
> i am new to cgi. Please let me know why I dont get the data printed?
> I have abc.cgi in /var/www/cgi-bin
>
> When the $cmd is "ls" I get the filenames when I visit localhost/cgi-bin/abc.cgi
> But when the $cmd is the snmpquerry, I get nothing on the page, though I get the desired output(value of sysContact.0) when I run the script in commandline.
>
> ----------------------------
> #! /usr/bin/perl
> print "Content-type: text/html\n\n";
> print <<"END OF PRINT";
> <html>
> <head><title>test</title></head>
> <body>
> END OF PRINT
> my $cmd = "snmpget 23.23.23.23 public sysContact.0";
> #my $cmd = "ls";
> my $res = qx!$cmd!;
> chomp($res);
> print <<"end of print";
> <center>
> $res
> </center>
> </body></html>
> end of print
> -------------------------------------
>
> TIA
> Tapas
>
> --
> To unsubscribe, e-mail: beginners-cgi-unsubscribe@perl.org
> For additional commands, e-mail: beginners-cgi-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>
-------------------------------------------------------------
Note the obsessive use of abbreviations and avoidance of
capital letters; this is a system invented by people to whom
repetitive stress disorder is what black lung is to miners.
Long names get worn down to three-letter nubbins, like stones
smoothed by a river.
---Neal Stephenson, on Unix filesystem naming conventions----
| |
| Vladimir D Belousov 2005-02-21, 8:55 am |
| .... But if you have enabled SuEXEC (see the `httpd -l` output), your CGI
scripts will run as user/group you specify.
Paul Archer wrote:
> This is a very common problem. When you run the script from the
> command line, you are running it with different privileges and a
> different path than when the web server runs it.
> Most likely, either the command is not in the path for CGI scripts
> (try setting $ENV{PATH} or calling the command with the full
> pathname), or the web server, which should run as 'nobody', doesn't
> have permission to run the command properly.
>
>
> 10:29am, TapasranjanMohapatra wrote:
>
>
> -------------------------------------------------------------
> Note the obsessive use of abbreviations and avoidance of
> capital letters; this is a system invented by people to whom
> repetitive stress disorder is what black lung is to miners.
> Long names get worn down to three-letter nubbins, like stones
> smoothed by a river.
> ---Neal Stephenson, on Unix filesystem naming conventions----
>
| |
| Vladimir D Belousov 2005-02-21, 8:55 am |
| .... But if you have enabled SuEXEC (see the output `httpd -l`), your
script will run as user/group you specify.
Paul Archer wrote:
> This is a very common problem. When you run the script from the
> command line, you are running it with different privileges and a
> different path than when the web server runs it.
> Most likely, either the command is not in the path for CGI scripts
> (try setting $ENV{PATH} or calling the command with the full
> pathname), or the web server, which should run as 'nobody', doesn't
> have permission to run the command properly.
>
>
> 10:29am, TapasranjanMohapatra wrote:
>
>
> -------------------------------------------------------------
> Note the obsessive use of abbreviations and avoidance of
> capital letters; this is a system invented by people to whom
> repetitive stress disorder is what black lung is to miners.
> Long names get worn down to three-letter nubbins, like stones
> smoothed by a river.
> ---Neal Stephenson, on Unix filesystem naming conventions----
>
| |
| Paul Archer 2005-02-21, 3:55 pm |
|
Beware that this can be a fix that causes more problems. It's very tempting
to let the web server run as root--which opens up a big can of security
worms.
Paul
11:25am, Vladimir D Belousov wrote:
> ... But if you have enabled SuEXEC (see the output `httpd -l`), your script
> will run as user/group you specify.
>
> Paul Archer wrote:
>
>
----------------------------------------------------------------
Q: What do Winnie-the-Pooh and John the Baptist have in common?
A: Their middle name.
----------------------------------------------------------------
| |
| Vladimir D Belousov 2005-02-21, 3:55 pm |
| Why root? Just the user who has permissions to do something.
Paul Archer wrote:
>
> Beware that this can be a fix that causes more problems. It's very
> tempting to let the web server run as root--which opens up a big can
> of security worms.
>
> Paul
>
> 11:25am, Vladimir D Belousov wrote:
>
>
> ----------------------------------------------------------------
> Q: What do Winnie-the-Pooh and John the Baptist have in common?
> A: Their middle name.
> ----------------------------------------------------------------
>
| |
| Paul Archer 2005-02-21, 8:55 pm |
| I'm not saying you have to become root. I'm simply saying that for some
people it's a temptation ("If I change this to root, I don't have to worry
about ownership problems ever again").
6:21pm, Vladimir D Belousov wrote:
> Why root? Just the user who has permissions to do something.
>
> Paul Archer wrote:
>
>
---------------------------------------------------------------------
On the side of the software box, in the "System Requirements" section,
it said "Requires Windows 95 or better". So I installed Linux.
---------------------------------------------------------------------
|
|
|
|
|