通过SSH和PHP网页在远程服务器上执行Perl脚本


Execute Perl script on a remote server through SSH with PHP WebPage

我需要通过SSH在服务器a上启动一个带有PHP网页的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);

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

谢谢你的帮助

我的建议-使用phpseclib,一个PHP SSH实现:

<?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()通常在主机上出于安全原因被禁用