通过SSH与PHP WebPage在远程服务器上执行Perl脚本

时间:2015-06-04 10:37:54

标签: php perl remote-server

我需要在服务器B上使用PHP WebPage通过SSH在服务器B上启动Perl脚本。

我的命令如下:

$cmd_string="ssh user@serverB 'perl path/to/script.pl param1 param2'";

我在PHP脚本中都尝试过但没有任何事情发生:

exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd_string, $outputfile, $pidfile));
exec($cmd_string, $output);

通过终端运行此命令效果很好。

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

我的建议 - 使用phpseclib, a PHP SSH implementation

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

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

echo $ssh->exec('perl path/to/script.pl param1 param2');
?>
出于安全原因,

exec()通常在主机上禁用。

相关问题