简体   繁体   中英

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.

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:

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 :

<?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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM