将从远程计算机运行shell脚本的PHP脚本

时间:2013-01-24 07:23:14

标签: php

我一直在网上搜索如何在php中实现它。场景是我的php应用程序在计算机A中,我要执行的shell脚本文件在计算机B中。我希望我的计算机A中的php应用程序在计算机B中执行shell脚本文件。

我知道权限在此方面起着非常重要的作用,但我可以访问计算机B,因此设置权限没有问题。

顺便说一句,计算机A是Windows服务器而计算机B是kubuntu。有没有人有想法?谢谢

2 个答案:

答案 0 :(得分:1)

您可以在PHP中使用ssh函数来实现您正在寻找的东西,

参考http://php.net/manual/en/ssh2.requirements.php

答案 1 :(得分:1)

太糟糕了无法添加包,只是通过这个解决了它

public function execScript($connection, $script)
{

    // Execute script        
    exec("ssh $connection $script 2>&1", $output, $error);

    if ($error) {
        throw new Exception ("\nError: ".print_r($output, true));
    }

    return $output;
}