SSH / PHP help

Discussion in 'OT Technology' started by Mint, Jul 15, 2008.

  1. Mint

    Mint Active Member

    Joined:
    Jun 22, 2007
    Messages:
    5,208
    Likes Received:
    0
    Location:
    Southern Cali
    Okay here's what I'm doing - I'm trying to get this php page to connect to a Unix box and (an ESX box)
    and execute some commands.

    It connects fine, and even executes SOME commands just fine.
    Heres the code:

    Code:
    <?php
    
    $doit = "vim-cmd vmsvc/getallvms" ;
    $connection = ssh2_connect('192.168.10.9', 22);
    ssh2_auth_password($connection, 'root', 'mysecret');
    
    $cmd = shell_exec($doit)
    
    if ($cmd){echo('pass <br><br>');}
    else{echo('fail<br><br>');}
    echo ($cmd);
    
     ?>
    
    Now that if statement is solely to see if the commands are being executed.
    Now If I put $doit to a normal 'ls -lart' or something similar (a standard command) it works fine with the shell_exec.
    and returns the PASS and echos the entire CMD return for ls

    However if I try to use the ESX command vim-cmd vmsvc/getallvms - it fails and nothing returns.
    I've also tried putting my vim-cmd command into a shell script and setting

    Code:
    $dir = "bash vimon.sh" 
    $dir = "./vimon.sh"
    $dir = "sh vimon.sh"
    
    None of those work either.

    Now, also if i use the ssh2_exec function it returns "Resource id #3" and "PASS"
    But no matter what command is executes it always returns that "Resource id #3" - even the LS doesnt work when i use that function.

    Also its worth noting that if I manually SSH through a terminal I can execute all these commands just fine.

    Thanks.
     
  2. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    so it doesn't say pass or fail? according to php.net this command uses PHP memory and if it runs over the max it'll just die. try increasing memory_limit in your php.ini file.
     
  3. Mint

    Mint Active Member

    Joined:
    Jun 22, 2007
    Messages:
    5,208
    Likes Received:
    0
    Location:
    Southern Cali
    It says Fail when I execute using shell_exec When trying to run the .sh files
    or when i try to use the vim-cmd command - just says fail like its not even executing the command.

    However if I use shell_exec to run a ls -lart (much larger return than that of VIM-cmd) it says Pass and prints the return.

    However, if i use ssh2_exec it PASS's but every return is "Resource ID #3"
     

Share This Page