[ Main Table Of Contents | Table Of Contents | Keyword Index ]

shellspy_module_punk::sshrun(0) 0.1.0 doc "punk::sshrun tclssh clone"

Name

shellspy_module_punk::sshrun - Tcl procedures to execute tcl scripts in remote hosts

Table Of Contents

Synopsis

Description

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

overview of punk::sshrun

SYNOPSIS

package require punk::sshrun

-

punk::sshrun::connect [-t <tclsh_name>] [-- <ssh_options>] [<user>@]<host>

Defaults: -t tclsh

dependencies

packages used by punk::sshrun

  • Tcl 8.6

  • cmdline

API

Namespace punk::sshrun

Core API functions for punk::sshrun

connect args

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}

disconnect host

Must be called last. Closes the filehandle opened by connect.

push host script

<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

send host

This proc does the equivalent of a

       puts <filehandle> [join <script_list> \n]
       flush <filehandle>
   
send_exit host

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)

pop_line host line_varname

After executing a "send", this can be used to read one line of output. The proc does the equivalent of

       [gets <filehandle> line]
   
pop_all host output_varname

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)

pop_read host numbytes output_varname

Returns: numbytes read. If numbytes is not positive, then read is called without the numbytes argument.

hfileevent host readable_writable script

Equivalent to:

       fileevent <filehandle> $readable_writable $script
   
hconfigure host args
rexec host script output_varname

shortcut for:

      ssh::rexec_nopop $host $script
      ssh::pop_all $host outputvar
   
get_filehandle host

Namespace punk::sshrun::lib

Secondary functions that are part of the API

Internal

Namespace punk::sshrun::system

Internal functions that are not part of the API

Keywords

module, ssh