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
https://forums.phpfreaks.com/topic/114890-ssh-php-problems/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.