Secure iNet Factory

com.jscape.inet.ssh
Class SshScript

java.lang.Object
  extended by com.jscape.inet.ssh.SshScript
All Implemented Interfaces:
java.io.Serializable

public class SshScript
extends java.lang.Object
implements java.io.Serializable

The SshScript class provides a simple way of running a set of batch scripted commands against a SSH server. When communicating with a SSH server in interactive mode (non-batch) the user must wait until the completion of the previous command before entering a new command. In interactive mode the completion of the previous command is generally indicated by the display of the shell prompt which allows the user to enter the next command. The SshScript class is especially useful in automating SSH procedures such as user login and command execution.

For simple scripting tasks see the SshSession class.

Example Usage:

 // create new Ssh instance
 Ssh Ssh = new Ssh(hostname,username,password);

 // create new SshScript instance
 SshScript script = new SshScript(Ssh);

 // create task to perform a directory listing

 SshTask dirListing = new SshTask("$","ls -al","$");

 // add task to script
 script.addTask(dirListing);

 // connect to SSH server and execute SshScript
 ssh.connect();

 // disconnect from SSH server
 ssh.disconnect();
 

See Also:
SshSession, Serialized Form

Constructor Summary
SshScript(Ssh ssh)
          Constructs a new SshScript instance.
SshScript(Ssh ssh, java.lang.String terminator)
          Constructs a new SshScript instance.
 
Method Summary
 void addSshScriptListener(SshScriptListener listener)
          Adds a SshScriptListener to this SshScript.
 void addTask(SshTask task)
          Adds a SshTask to this SshScript.
 void clear()
          Clears all tasks from the script.
 SshTask getTask(java.lang.String name)
          Gets the named SshTask based on the name attribute of a SshTask.
 boolean isComplete()
          Checks whether this SshScript has completed execution of all SshTask.
 boolean isEmpty()
          Checks if there are any SshTask bound to this SshScript
 void removeSshScriptListener(SshScriptListener listener)
          Removes a SshScriptListener from this SshScript
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SshScript

public SshScript(Ssh ssh)
Constructs a new SshScript instance.

Parameters:
ssh - - the Ssh instance this SshScript is bound to.
See Also:
Ssh

SshScript

public SshScript(Ssh ssh,
                 java.lang.String terminator)
Constructs a new SshScript instance. When adding a new SshTask using addTask method the SshTask#setTerminator method is invoked with the terminator value. This is a convenient method of setting the terminator globally for all SshTask added to a SshScript instead of setting it for each SshTask.

Parameters:
ssh - - Ssh instance this SshScript is bound to.
terminator - the line terminator to use when executing command for a SshTask
See Also:
Ssh, SshTask, addTask(com.jscape.inet.ssh.SshTask)
Method Detail

isEmpty

public boolean isEmpty()
Checks if there are any SshTask bound to this SshScript

Returns:
true if there are SshTask, false otherwise

addTask

public void addTask(SshTask task)
Adds a SshTask to this SshScript.

Parameters:
task - the SshTask to add
See Also:
SshTask

getTask

public SshTask getTask(java.lang.String name)
Gets the named SshTask based on the name attribute of a SshTask.

Parameters:
name - the name of the SshTask to retrieve.
Returns:
the named SshTask if found, null otherwise
See Also:
SshTask

clear

public void clear()
Clears all tasks from the script.


addSshScriptListener

public void addSshScriptListener(SshScriptListener listener)
Adds a SshScriptListener to this SshScript.

Parameters:
listener - the SshScriptListener instance to add
See Also:
SshScriptListener

removeSshScriptListener

public void removeSshScriptListener(SshScriptListener listener)
Removes a SshScriptListener from this SshScript

Parameters:
listener - the SshScriptListener instance to remove
See Also:
SshScriptListener

isComplete

public boolean isComplete()
Checks whether this SshScript has completed execution of all SshTask.

Returns:
true if all tasks executed, false otherwise

Secure iNet Factory

Copyright © JSCAPE LLC. 1999-2011. All Rights Reserved