Jump to content

SSH / PHP problems


FreshMint

Recommended Posts

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:

 

<?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

 

$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.


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.