sunlabs.brazil.ssh
Class SshTemplate
java.lang.Object
sunlabs.brazil.template.Template
sunlabs.brazil.ssh.SshTemplate (view source)
- All Implemented Interfaces:
- TemplateInterface
public class SshTemplate
- extends Template
Template to start an ssh connecton to a server.
SshTemplate
public SshTemplate()
tag_ssh
public void tag_ssh(RewriteContext hr)
- Simple version: one connection per session, no port forwarding.
This implements the ssh tag:
<ssh
user=xx host=xx pass=xx [key=xx id=xx] stdinQ=xx stdoutQ=xx
unbuffered=true|false] />
<ssh close="x" />
user=xx host=xx pass=xx [key=xxx id=xx] stdinQ=xx stdoutQ=xx
unbuffered=true|false] />
Alternately, one a connection is opened (using defer=true)
Commands may by run synchronously, and have their output
captured in the variables "stdout" and "stderr".
<ssh id=xx user=xx host=xx pass=xx [key=xx] defer=true>
<sshcommand id=xx command=xx [stdin=xx]>
<ssh close=xx>
Tag attributes:
- host
- The host to ssh to
- port
- The server port (defaults to 22)
- user
- The user name
- pass
- The user's password, if using password authentication, or
the password for the private key if "key" is specified.
- key
- The user's private key, in PEM format. If "key" is provided,
the "pass" option (if any) is used to decrypt "key". If no key
is provided, then password based authentication using "user"
and "pass" is attempted instead.
- id
- A unique identifier for this session. This value will be present
in all Q'd output, enabling multiple sessions to share the same
output Q's.
- command
- If specified, this command is run on the remote side, otherwise
an interactive shell is created.
- stdinQ
- stdoutQ
- The Queues (See QueueTemplate) to use to communicate with
the ssh streams. The stderr/stdout of the ssh connection is sent
to the "stdOutQ", and is accessible using <dequeue name=[stdOutQ]>.
the output will be in the queue element "line".
Data can be sent to the stdin of the ssh connection with:
<enqueue name=[stdinQ] data="line ..." />
- unbuffered
- by default, the "stderr" from the ssh stream is unbuffered, and
the "stdout" stream is line buffered. Setting "unbuffered" to true
sets stderr to unbuffered as well.
- close=[id]
The connection specified by "id" (if any) is closed. When "close"
is specified, all other parameters are ignored.
If authentication failed, the property [id].error is set.
When ssh terminates, the "error" property of queue entry is set.
See also the example included with the distribution.
tag_sshcommand
public void tag_sshcommand(RewriteContext hr)
- Run a command synchronously from an existing ssh connection.
<sshcommand id=xxx command=xxx [stdin=xxx timeout=sec]>.
The "Command" is run against "id" (created with <ssh ...>).
If "stdin" is supplied, it is sent to the stdin of the command.
The command is run to completion, and the results are placed into
the variables "stdout", "stderr", "status" and (sometime) error.
Don't forget
to run "<ssh close=id>" when done with this connection.
close
public void close(String id)