如何通过php代码以首选格式在远程节点上调用perl脚本


How to call a perl script on the remote node in a preferred format through a php code

在对远程节点执行ssh后,我需要在该节点上调用perl脚本。我正在尝试执行以下命令

$output=exec('$configpath/perl master_program.pl --backupID $id');

在我传递路径和ID值的地方,perl程序只需要以这种格式调用,有人能确认这是否有效吗?否则,还有其他解决方案吗。

我正在粘贴下面的完整代码:

<?php   function create_ssh_connection($ip,$user,$pass,$configpath,$id){
                $connection = FALSE;
            $connection = ssh2_connect($ip, 22);
    if($connection===FALSE){
        #logger('Unable to establish connection with the host: ');
        return FALSE;
    }       
        if(!ssh2_auth_password($connection, $user, $pass)){
            #logger('User Password Authentication failed. User: '.$user.' IP: '.$ip.' '.$pass);
            return FALSE;}
    $output=exec('$configpath/perl master_program.pl --backupID $id');  //system call
        #print "<pre>$output</pre>'n";

}
    $ip=$argv[1];
    $user=$argv[2];
    $pass=$argv[3]; 
    $configpath=$argv[4];
    $id=$argv[5];
    $stream1=create_ssh_connection($ip,$user,$pass,$configpath,$id);
?>

上面的代码将在不同的shell脚本中通过传递所需的ip、密码等进行调用。

谢谢

根据php.net上ssh2文档的快速阅读,您不想使用ssh_auth_password(),这只是为了验证用户。

看起来您想要做的是使用ssh_connect()连接到远程服务器,然后使用ssh_exec()运行您的perl程序。