简体   繁体   English

如何通过登录另一个服务器从php执行tcl脚本

[英]How to execute a tcl script from php via logging into another server

I am working on a project where from my front-end (written in php) needs to login to a server and execute a tcl script which can run only in that server. 我正在一个项目中,从我的前端(用php编写)需要登录到服务器并执行只能在该服务器上运行的tcl脚本。

So first I would like to generate a connection first and then execute the tcl in that established connection. 因此,首先我想先生成一个连接,然后在该已建立的连接中执行tcl。

I am not able to generate a connection to the server. 我无法生成与服务器的连接。

My php script is: 我的PHP脚本是:

<!DOCTYPE html>
<html>
    <body>
        <?php

        function print_procedure ($arg) {
            $array = array();
            echo exec('/usr/bin/tclsh ./$args',$array);

            for($i=0;$i<count($array);$i++)
            {
                echo "<br>";
                print_r($array[$i]);
                echo "<br>";
            }
            $script_name='test.tcl';
        }
        print_procedure($script_name);

        ?>
    </body>
</html>

Please help me out. 请帮帮我。 Thanks in advance. 提前致谢。

The easiest thing is to use ssh in its "run a remote command" mode. 最简单的方法是在“运行远程​​命令”模式下使用ssh

echo exec('ssh $remotehost /usr/bin/tclsh ./$args', $array);

This assumes that the script has already been uploaded to the remote host. 这假定脚本已被上载到远程主机。 If not, do that first with scp (a part of the same suite of programs as ssh ). 如果不是,请首先使用scp (与ssh相同的程序集的一部分)。

You'll then need to configure the account running that PHP script to be able to ssh to the remote host without entering a password. 然后,您需要配置运行该PHP脚本的帐户,以便能够在不输入密码的情况下SSH到远程主机。 A reasonably secure method is to set up ssh-agent with a key, but I do not know the details of making this method work with PHP. 一种合理的安全方法是使用密钥设置ssh-agent ,但我不知道使此方法与PHP一起使用的详细信息。 (Turning off passwords on the target machine would also work, but is scary in security terms!) (在目标计算机上关闭密码也可以,但是在安全性方面令人恐惧 !)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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