命令在SSH中通过MobaXterm工作,但在SSH中没有通过PHP找到?

时间:2015-08-04 17:30:24

标签: php linux bash ssh phpseclib

我正在尝试通过SSH(使用Net_SSH2类)连接到PHP代码中的服务器,并在远程服务器上运行许多命令。

远程服务器输出bash: runmqsc: command not found

奇怪的是,当我使用MobaXterm SSH连接时,在该服务器上找到完全相同的命令并起作用。

我验证了代码使用正确的主机名,用户和密码进行连接。

有什么想法吗?

这就是我在PHP中所做的:

$this->ssh = new Net_SSH2("myhost");
$this->ssh->login("myuser", "mypass");

$command = "runmqsc MyQmgr \n DEFINE QLOCAL(MY_QUEUE) \n end \n";
$this->ssh->exec($command);

1 个答案:

答案 0 :(得分:0)

你可能需要做更多这样的事情:

<?php
include('Net/SSH2.php');

$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('username', 'password')) {
    exit('Login Failed');
}

echo $ssh->read('username@username:~$');
$ssh->write("runmqsc MyQmgr\n"); // note the "\n"
echo $ssh->read('username@username:~$'); // or whatever the prompt is - does runmqsc have it's own prompt?
$ssh->write("DEFINE QLOCAL(MY_QUEUE)\n");
?>

...等...