shellspy_module_punk::sshrun - Tcl procedures to execute tcl scripts in remote hosts
This is a clone of tclssh by Jose F. Nieves
The original repo is at: https://bitbucket.org/noaaport/tclssh/src/master/
This version is namespaced under punk::sshrun specifically for the Punk shell project - and may lag the original project or diverge.
You are encouraged to use the original Tclssh source from the above URL for your own projects
overview of punk::sshrun
SYNOPSIS
package require punk::sshrun
-
punk::sshrun::connect [-t <tclsh_name>] [-- <ssh_options>] [<user>@]<host>
Defaults: -t tclsh
-
Core API functions for punk::sshrun
Must be called first.
This proc opens an io channel to the tclsh in the remote host (via ssh) that is kept in an internal variable for subsequent use.
The file handle can be retrieved if desired through the command: get_filehandle {host}
Must be called last. Closes the filehandle opened by connect.
<script> can be any tcl code.
For example, if the remote host is named "diablo"
ssh::push "diablo" "exec date" ssh::push "diablo" "exec uname -a"
The commands are note executed immediately. Instead, the "push" proc simply accumulates them in a list that is sent to the host when the "send" procedure is executed.
Each push proc inserts the newline '\n' character after each <script>
In the above example. Internally, each <script> is a member of a list, and when the "send" proc is invoked the entire script is constructed as a "join <list> \n
This proc does the equivalent of a
puts <filehandle> [join <script_list> \n] flush <filehandle>
This proc is similar to the above, but it "pushes" an exit command at the end of the script. The proc does the equivalent of
ssh::push <host> "exit" ssh::send <host>
The net effect if this is that the remote host's tclsh will exit, so that the filehandle receives an eof and we can use
[read <filehandle>]
to read the entire output at once (see the pop proc below)
After executing a "send", this can be used to read one line of output. The proc does the equivalent of
[gets <filehandle> line]
This proc does the equivalent of
while {[pop_line $host line] >=0} { puts $line; }
but all the output is returned as one string in output_varname.
It should be used only when we know that the remote host's tclsh will exit, so that the above code will detect the eof and exit
(see the send_exit proc above)
The function returns the number of lines read (0 if nothing is read before encoutering eof)
Returns: numbytes read. If numbytes is not positive, then read is called without the numbytes argument.
Equivalent to:
fileevent <filehandle> $readable_writable $script
shortcut for:
ssh::rexec_nopop $host $script ssh::pop_all $host outputvar
Internal functions that are not part of the API
Copyright © 2009