469,288 Members | 2,353 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,288 developers. It's quick & easy.

Weird system call behavior

Me
I'm looking for some insight to the following code. I don't understand why
when I uncomment the #$command="/usr/local/apache/cgi-bin/port-reset.exp
$portnumber"; and comment the ls command it does not execute successfully.
When the code is as below everything works fine, but switching the commented
lines cause it to fail. I send the results of $command to a file and it
looks fine, I can even copy and paste the output, as any user, and it
executes fine, it just won't execute successfully when I call it from a web
page. Any assistance would be appreciated.

## Code begins
print "Content-type: text/html\n\n";
print "<HTML><BODY bgcolor=#483d8b><FONT COLOR=\"yellow\">";
print "<CENTER>";

$portnumber = $in{'PORT'}; #Value passed in from the
/usr/local/apache/htdocs/port-reset/index.html page

#$command="/usr/local/apache/cgi-bin/port-reset.exp $portnumber"; ## This
command will only execute from a command line and not from within this
script
$command="/usr/bin/ls -al > /tmp/file2"; # This works fine, so I comment
this line, uncomment the above and the script fails. Why?

$result = system("$command");
if ($result) {
# $? is the exit code.
print "<h1>Unable to reset port $portnumber. Contact support.\n";
}
else {
#It exits 0 if successfully
print "<h1>Port $portnumber has been reset.";
}

################################################## ############
# This logs all page sent through the web
################################################## ############
$Time = localtime;
open(OUTFILE, ">>/usr/local/apache/logs/port-reset.logs");
print OUTFILE
("\"$Time\",\"$ENV{'REMOTE_ADDR'}\",\"$portnumber\ ",\"$command\"\n\"");
exit;
## Code ends
Jul 19 '05 #1
2 2637

"Me" <an*********@netzero.net> wrote in message
news:SE*********************@news20.bellglobal.com ...
I'm looking for some insight to the following code. I don't understand why
when I uncomment the #$command="/usr/local/apache/cgi-bin/port-reset.exp
$portnumber"; and comment the ls command it does not execute successfully.
When the code is as below everything works fine, but switching the commented lines cause it to fail. I send the results of $command to a file and it
looks fine, I can even copy and paste the output, as any user, and it
executes fine, it just won't execute successfully when I call it from a web page. Any assistance would be appreciated.

## Code begins
print "Content-type: text/html\n\n";
print "<HTML><BODY bgcolor=#483d8b><FONT COLOR=\"yellow\">";
print "<CENTER>";

$portnumber = $in{'PORT'}; #Value passed in from the
/usr/local/apache/htdocs/port-reset/index.html page

#$command="/usr/local/apache/cgi-bin/port-reset.exp $portnumber"; ## This
command will only execute from a command line and not from within this
script
$command="/usr/bin/ls -al > /tmp/file2"; # This works fine, so I comment
this line, uncomment the above and the script fails. Why?

$result = system("$command");
if ($result) {
# $? is the exit code.
print "<h1>Unable to reset port $portnumber. Contact support.\n";
}
else {
#It exits 0 if successfully
print "<h1>Port $portnumber has been reset.";
}

################################################## ############
# This logs all page sent through the web
################################################## ############
$Time = localtime;
open(OUTFILE, ">>/usr/local/apache/logs/port-reset.logs");
print OUTFILE
("\"$Time\",\"$ENV{'REMOTE_ADDR'}\",\"$portnumber\ ",\"$command\"\n\"");
exit;
## Code ends


Use sudo to give apache permission to execute.

--
-linux_lad
To verify that this post isn't forged, click here:
http://www.spoofproof.org/verify.php...543a73889e4706
Jul 19 '05 #2
Me
I can execute the command at the command line as nobody, so I don't think
using sudo would help. I'll give it a try anyways.

"-linux_lad" <john AT linuxlad DOT org> wrote in message
news:kf********************@giganews.com...

"Me" <an*********@netzero.net> wrote in message
news:SE*********************@news20.bellglobal.com ...
I'm looking for some insight to the following code. I don't understand why when I uncomment the #$command="/usr/local/apache/cgi-bin/port-reset.exp
$portnumber"; and comment the ls command it does not execute successfully. When the code is as below everything works fine, but switching the

commented
lines cause it to fail. I send the results of $command to a file and it
looks fine, I can even copy and paste the output, as any user, and it
executes fine, it just won't execute successfully when I call it from a

web
page. Any assistance would be appreciated.

## Code begins
print "Content-type: text/html\n\n";
print "<HTML><BODY bgcolor=#483d8b><FONT COLOR=\"yellow\">";
print "<CENTER>";

$portnumber = $in{'PORT'}; #Value passed in from the
/usr/local/apache/htdocs/port-reset/index.html page

#$command="/usr/local/apache/cgi-bin/port-reset.exp $portnumber"; ## This command will only execute from a command line and not from within this
script
$command="/usr/bin/ls -al > /tmp/file2"; # This works fine, so I comment this line, uncomment the above and the script fails. Why?

$result = system("$command");
if ($result) {
# $? is the exit code.
print "<h1>Unable to reset port $portnumber. Contact support.\n";
}
else {
#It exits 0 if successfully
print "<h1>Port $portnumber has been reset.";
}

################################################## ############
# This logs all page sent through the web
################################################## ############
$Time = localtime;
open(OUTFILE, ">>/usr/local/apache/logs/port-reset.logs");
print OUTFILE
("\"$Time\",\"$ENV{'REMOTE_ADDR'}\",\"$portnumber\ ",\"$command\"\n\"");
exit;
## Code ends


Use sudo to give apache permission to execute.

--
-linux_lad
To verify that this post isn't forged, click here:
http://www.spoofproof.org/verify.php...543a73889e4706

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by redneck_kiwi | last post: by
6 posts views Thread by Angel Mazo | last post: by
11 posts views Thread by ncf | last post: by
1 post views Thread by Jonathan Yong | last post: by
3 posts views Thread by Wayne Dyer | last post: by
8 posts views Thread by XYZ | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.