Results 1 to 5 of 5

Thread: PHP executing a bash script

  1. #1
    Join Date
    Nov 2005
    Location
    N. Ireland
    Beans
    209
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    PHP executing a bash script

    Hi all

    I have written a bash script that wgets the "connected users" page of my wireless router. It then parses out the connected macs and and displays if the user is online or not:

    Code:
    rm -rf /home/nino/macs
    rm -rf /home/nino/test
    wget -nv -q --http-user=[USERNAME]-O /home/nino/ad-admin-client.htm --http-password=[PASSWORD] http://192.168.11.1/advance/ad-admin-client.htm 
    cat /home/nino/ad-admin-client.htm | grep 00: >> /home/nino/macs
    cat /home/nino/macs | cut -c84-100 > /home/nino/cutup
    rm /home/nino/ad-admin-client.htm
    
    cat  /home/nino/cutup | grep 00:13:CE:2D:A3:A2
    
    echo "<BR>" >> /home/nino/test
    
    case $? in
    0)
    echo "NINO-IPW ONLINE <BR>" >> /home/nino/test
    ;;
    1)
    echo "NINO_IPW OFFLINE<BR>" >> /home/nino/test
    ;;
    esac
    
    cat /home/nino/cutup | grep 00:20:A6:58:97:A7
    
    case $? in
    0)
    echo "NINO-PROXIM ONLINE<BR>" >> /home/nino/test
    ;;
    1)
    echo "NINO_PROXIM OFFLINE<BR>" >> /home/nino/test
    ;;
    esac
    
    
    
    cat  /home/nino/cutup | grep 00:0A:95:F1:B1:81
    
    case $? in
    0)
    echo "DARREN ONLINE<BR>" >> /home/nino/test
    ;;
    1)
    echo "DARREN OFFLINE<BR>" >> /home/nino/test
    ;;
    esac
    
    cat /home/nino/cutup | grep 00:0F:B5:09:2D:0B
    
    case $? in
    0)
    echo "DOM ONLINE<BR>" >> /home/nino/test
    ;;
    1)
    echo "DOM OFFLINE<BR>" >> /home/nino/test
    ;;
    esac
    
    cat /home/nino/cutup | grep 00:0F:B5:0A:4F:8B
    
    case $? in
    0)
    echo "REBECCA ONLINE<BR>" >> /home/nino/test
    ;;
    1)
    echo "REBECCA OFFLINE<BR>" >> /home/nino/test
    ;;
    esac
    
    cat /home/nino/cutup | grep 00:0F:B5:42:0C:D2
    
    case $? in
    0)
    echo "NINO_DESKTOP ONLINE<BR>" >> /home/nino/test
    ;;
    1)
    echo "NINO_DESKTOP OFFLINE<BR>" >> /home/nino/test
    ;;
    esac
    
    cat /home/nino/cutup | grep 00:0F:B5:42:0C:D4
    
    case $? in
    0)
    echo "CONTROL ONLINE<BR>" >> /home/nino/test
    ;;
    1)
    echo "CONTROL OFFLINE<BR>" >> /home/nino/test
    ;;
    esac
    rm -f /home/nino/cutup
    rm /home/nino/macs
    the php code im using is:

    execute the script and output it to /home/nino/test

    Code:
    <?php  
      $test = shell_exec('/bin/online_users_for_site');
      echo($test);
    ?>
    then echo out the file:

    Code:
    <?php  
      $data = shell_exec('cat /home/nino/test');
      echo($data);
    ?>
    When i execure the script on the server directly it runs and generates the file with the info. however when i try to do it via the php i get nothing. Possible file permissions? is there a better way to execute commands on a server and display the output

    Thanks for any help

    nino
    Last edited by ninocass; December 2nd, 2006 at 01:06 PM. Reason: Added incorrect code
    1. A computer is a machine for rearranging bits
    2. The Internet is a machine for moving bits from one place to another very cheaply and quickly

  2. #2
    Join Date
    Nov 2005
    Location
    N. Ireland
    Beans
    209
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: PHP executing a bash script

    had a further look at the script and it seem when the website calls the wget part it dosent execute, any ideas?

    cheers

    Nino
    1. A computer is a machine for rearranging bits
    2. The Internet is a machine for moving bits from one place to another very cheaply and quickly

  3. #3
    Join Date
    Nov 2004
    Location
    Clemson, SC
    Beans
    271

    Re: PHP executing a bash script

    Quote Originally Posted by ninocass View Post
    had a further look at the script and it seem when the website calls the wget part it dosent execute, any ideas?

    cheers

    Nino
    I know nothing of PHP, but maybe the $PATH variable isn't set. Try /usr/bin/wget instead.

  4. #4
    Join Date
    Nov 2005
    Location
    N. Ireland
    Beans
    209
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: PHP executing a bash script

    yea it needed an absolute path also the files were being make under the user www-data so i made a temp dir chown'ed it to www-data and put all the the files needed in there

    working a treat now
    1. A computer is a machine for rearranging bits
    2. The Internet is a machine for moving bits from one place to another very cheaply and quickly

  5. #5
    Join Date
    Mar 2006
    Location
    Toronto, Canada
    Beans
    855

    Re: PHP executing a bash script


Bookmarks

Posting Permissions

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