带有ssh2_exec的PHP没有执行远程脚本

时间:2018-02-20 17:41:49

标签: php linux shell ssh

我是PHP新手并尝试创建一个简单的网页,它接受服务器名称/主机名并在远程计算机上执行shell脚本。它适用于简单的Linux命令(即uname,hostname),但是当我尝试执行接受两个参数并点击提交按钮的shell脚本时,没有任何内容被执行

<?php

$server = $_GET['server'];
$username = “testuser”; 
$password = “password”;
$command  = 'sudo test.sh -a -2018.0220’; 


$connection = ssh2_connect($server, 22);


ssh2_auth_password($connection, $username, $password);


$stream = ssh2_exec($connection, $command);


stream_set_blocking($stream, true);


$output = stream_get_contents($stream);


echo "<pre>{$output}</pre>";
?>

<form action="patching.php" method="GET">
Name: <input type="text" name="server"><br><br>
<input type="submit" value="Submit">
</form>

我读了一些早先的帖子,他们建议使用escapeshellarg,我试过但没有运气

$var1 = escapeshellarg("-a");
$var2 = escapeshellarg("-2018.0220");

$command  = 'sudo /usr/local/libexec/system_update.sh $var1 $var2';

0 个答案:

没有答案
相关问题