Weird system call behavior

Discussion in 'Perl' started by Me, Oct 17, 2003.

  1. Me

    Me Guest

    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
     
    Me, Oct 17, 2003
    #1
    1. Advertising

  2. Me

    -linux_lad Guest

    "Me" <> wrote in message
    news:SEUjb.10303$...
    > 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?sig=46f32579168fa7ba8c543a73889e4706
     
    -linux_lad, Oct 17, 2003
    #2
    1. Advertising

  3. Me

    Me Guest

    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:...
    >
    > "Me" <> wrote in message
    > news:SEUjb.10303$...
    > > 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?sig=46f32579168fa7ba8c543a73889e4706
    >
    >
     
    Me, Oct 17, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dorayme
    Replies:
    1
    Views:
    655
    richard
    Jan 21, 2011
  2. richard
    Replies:
    0
    Views:
    615
    richard
    Jan 21, 2011
  3. richard
    Replies:
    0
    Views:
    660
    richard
    Jan 21, 2011
  4. Beauregard T. Shagnasty

    Re: A Weird Appearance for a Weird Site

    Beauregard T. Shagnasty, Jan 21, 2011, in forum: HTML
    Replies:
    1
    Views:
    462
    Captain Paralytic
    Jan 21, 2011
  5. David Segall
    Replies:
    0
    Views:
    650
    David Segall
    Jan 22, 2011
Loading...

Share This Page