[英]Execute Perl script on a remote server through SSH with PHP WebPage
I need to launch a Perl script on server B from server A with a PHP WebPage through SSH. 我需要通过SSH通过PHP WebPage从服务器A在服务器B上启动Perl脚本。
My command looks like: 我的命令如下所示:
$cmd_string="ssh user@serverB 'perl path/to/script.pl param1 param2'";
I tried both inside PHP script but nothing happen: 我在PHP脚本中都尝试了两次,但没有任何反应:
exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd_string, $outputfile, $pidfile));
exec($cmd_string, $output);
Running this command through terminal works just well. 通过终端运行此命令效果很好。
Thanks for your help 谢谢你的帮助
My recommendation - use phpseclib, a PHP SSH implementation : 我的建议-使用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() is often disabled on hosts for security reasons. 出于安全原因,通常在主机上禁用exec()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.