简体   繁体   中英

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.

So first I would like to generate a connection first and then execute the tcl in that established connection.

I am not able to generate a connection to the server.

My php script is:

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

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

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. 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. (Turning off passwords on the target machine would also work, but is scary in security terms!)

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