Weird system call behavior

From: Me (anonymous35_at_netzero.net)
Date: 10/17/03


Date: Fri, 17 Oct 2003 12:19:54 -0400

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



Relevant Pages

  • Re: port forwarding with IP TABLES - bad argument
    ... I did some google searches for this ("iptables prerouting"). ... command does look ok, but I don't see a lot of people specify a port ... send it to that new machine with the same 10700 portnumber. ...
    (RedHat)
  • Re: Most dependable way to run system commands
    ... Eventually I'd like to bring the execution of a few system commands ... specific execution issue (it dealt more with executing Perl code)). ... Unix and many similar systems, the exit status is an integer, with 0 ... variable after running a command via system or backticks. ...
    (perl.beginners)
  • Re: very slow cursor in CMD window w/Text editor?
    ... REM MS-DOS-based application, Windows runs COMMAND.COM. ... To run CMD.EXE, the Windows command prompt, ... The exit command is an internal command part of command.com or cmd.exe. ...
    (microsoft.public.windowsxp.general)
  • Re: difference between the -o and || conditionals.
    ... you are running a first "[" command with ... equal to the number whose string representation is in its third ... a non-0 exit status otherwise. ... the cat and grep commands are run and its (possibly ...
    (comp.unix.shell)
  • [SLE] Printing help needed
    ... I broke my printing somehow. ... renderer command line returned an unrecognized error code 255.", exit ... printing through Kprinter and directly, command line, etc.). ... error on renderer command line or PostScript error. ...
    (SuSE)