Menu

How remotescript works and about Direct mode

poilou

How does remotescript basically works ? And what is "Direct Mode" ?

LibSsh2 is a beautiful library which contains two functions that are able to execute a simple command on a remote host : ssh2_exec and ssh2_shell.

The difference between thoses two functions is that the second one ask for a shell to the server and the first not.

The common point between these two func is that they don't wait that the prompt is back to execute the following command, even used with the stream_set_blocking option.

First, a simple (but bad) solution consist to "echo" a flag a the end of each line of the script, and then wait for the flag to be echoed before of sending the following line. But that cannot do the trick because you cannot use this kind of command in your script anymore :
~
if [ $? == 0 ]
~
which will always return 0 as long as there is an "echo" just before.

Actually the only solution seems to send the script in a remote temporary file and then execute it directly from there. That's the default mode used in remotescript.
The script is written in a file which is then sent via scp to the remote host, and then a remote shell is launched to execute the script and then to capture the resulting stream.

The major problem is now that you need a small place to store the script on each host : the server and the client.

The Direct mode allow you to execute a bunch of commands directly in a shell in the same way as you would do if you typed the command by yourself, without waiting for the prompt to write the following command. It could be useful for device which disallow writing in temporary folder.

Summary :
1. Default mode execute a script file with all your commands inside (just like a shell script context)
2. Direct mode send each command one after the other to the command prompt, without waiting that the previous command is done. (Just like a stupid command prompt context)

Globally, test thoses functionnality first, and check that the result corresponds to the result you were waiting for.


Related

Wiki: Home

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.