我正在尝试执行一个简单的shell命令并在网页上打印结果,但结果是空的.下面是我发现的一点代码但到目前为止没有任何工作.
<?php
$server = "myserver";
$username = "myadmin";
$command = "ps";
$str = "ssh " .$username. "@" .$server. " " .$command;
exec($str, $output);
echo '<pre>';
print_r($output);
echo '</pre>';
?>
Run Code Online (Sandbox Code Playgroud)
试试phpseclib,那就行了.
<?php
include('Net/SSH2.php');
$server = "myserver";
$username = "myadmin";
$password = "mypass";
$command = "ps";
$ssh = new Net_SSH2($server);
if (!$ssh->login($username, $password)) {
exit('Login Failed');
}
echo $ssh->exec($command);
?>
Run Code Online (Sandbox Code Playgroud)