Results 1 to 4 of 4

Thread: shell_exec

  1. #1
    Join Date
    Sep 2003
    Location
    ZA
    Posts
    24

    Unhappy Unanswered: shell_exec

    Good Morning Ladies and Gentleman,

    I'm having a few problem using a variable within the shell_exec function .
    Within the code i determine the Clients Remote IP Address using

    $remoteaddr = $_SERVER['REMOTE_ADDR'];

    That then gives me the IP Addy. What i am then trying to do
    is ping that IP Address.

    $test = shell_exec('ping -c 5 $remoteaddr');
    echo $test;

    However this does not work , it results in a blank page and an error in the /var/log/httpd/error_log file .

    The error is :

    Usage: ping [-LRUbdfnqrvVaA] [-c count] [-i interval] [-w deadline]
    [-p pattern] [-s packetsize] [-t ttl] [-I interface or address]
    [-M mtu discovery hint] [-S sndbuf]
    [ -T timestamp option ] [ -Q tos ] [hop1 ...] destination

    which makes me believe that the ping is started but without the IP which is stored as the variable. So for some reason the variable stored within the ('') is not being seen.

    Any ideas ?

    Regards

    Ronald

  2. #2
    Join Date
    Feb 2002
    Location
    San Francisco, CA
    Posts
    441
    try running;

    PHP Code:
    echo $test shell_exec('ping -c 5 $remoteaddr');
    echo 
    "\n$test"

  3. #3
    Join Date
    Aug 2004
    Posts
    1

    shell_exec

    You are correct about your variable within the '' not being seen. PHP interprets strings in '' differently than those in "". Easy way is to just change to "" and then the variable substitution happens.

    Marshall

  4. #4
    Join Date
    Sep 2003
    Location
    ZA
    Posts
    24

    Smile shell_exec

    Hi there Marshall, thanx for the help , the "" sorted out the problem . Do you know of any resources that would explain the difference between '' & "" . I thought that the reason might be that when shell_exec('ping blahblah'); would be because the linux shell stores it's variables in "" opposed to '' .
    ????

    Am i on the right track ??

    regards

    ./ronald

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •