com.hp.ucmdb.discovery.library.clients.shell
Class ShellClient

java.lang.Object
  extended by com.hp.ucmdb.discovery.library.clients.BaseClient
      extended by com.hp.ucmdb.discovery.library.clients.shell.ShellClient
Direct Known Subclasses:
NTCMDClient, SiebelClient, SSHClient, TelnetClient

public abstract class ShellClient
extends BaseClient

ShellClient runs shell commands. Thd principle methods are executeCmd and executeCmdWithTimeOut. The output of these methods is the console output of shell this client represents.


        # Example: Creating a telnet client
        client = Framework.getClientFactory(ClientsConsts.TELNET_PROTOCOL_NAME).createClient()
        output = client.executeCmd('df -P')
 

See Also:
com.hp.ucmdb.discovery.probe.clients.ClientsConsts, ClientFactory

Field Summary
static java.lang.String UNIX_CMD_SEPARATOR
           
static java.lang.String WIN_CMD_SEPARATOR
           
 
Fields inherited from class com.hp.ucmdb.discovery.library.clients.BaseClient
CREDENTIALS_ID, ENCODING
 
Constructor Summary
ShellClient(ClientsFrameworkImpl framework, java.util.Properties props, java.lang.String clientType)
           
 
Method Summary
 boolean canCopyFile()
           
 boolean deleteFile(java.lang.String remoteFileName, java.lang.String remoteShareName)
           
 java.lang.String executeCmd(java.lang.String cmd)
          Runs the specified command.
 java.lang.String executeCmd(java.lang.String cmd, boolean readUntilTimeout)
          Runs the specified command until completion or timeout.
 java.lang.String executeCmd(java.lang.String cmd, int cmdTimeout)
          Runs the specified command until completion or the specified timeout.
 java.lang.String executeCmd(java.lang.String cmd, int cmdTimeout, boolean readUntilTimeout)
          Runs the specified command until completion or the specified timeout.
 java.lang.String executeCmdWithTimeOut(java.lang.String cmd)
          Runs the specified command until completion or timeout.
 java.lang.String getFile(java.lang.String remoteFileName, java.lang.String remoteShareName)
           
 byte[] getLastCommandOutputBytes()
           
 int getMaxCommandLength()
          Returns the maximum length (bytes) of a command that can be sent to this client.
 java.lang.String getServerPort()
          Returns the server port from the protocol properties.
 java.lang.String getWelcomeBuffer()
           
 java.lang.String putFile(java.lang.String localFileName, java.lang.String remoteShareName)
           
 void setCharset(java.nio.charset.Charset charset)
           
 void setMaxCommandLength(int maxCommandLength)
          Sets the maximum length (bytes) of a command that can be sent to this client.
 
Methods inherited from class com.hp.ucmdb.discovery.library.clients.BaseClient
close, getClientType, getCredentialId, getIpAddress, getProperty, getShellCmdSeperator, getSudoCommands, getSudoPaths, getTimeout, getUserName, isConnected, supportsSudo
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNIX_CMD_SEPARATOR

public static final java.lang.String UNIX_CMD_SEPARATOR
See Also:
Constant Field Values

WIN_CMD_SEPARATOR

public static final java.lang.String WIN_CMD_SEPARATOR
See Also:
Constant Field Values
Constructor Detail

ShellClient

public ShellClient(ClientsFrameworkImpl framework,
                   java.util.Properties props,
                   java.lang.String clientType)
            throws java.lang.Exception
Throws:
java.lang.Exception
Method Detail

getWelcomeBuffer

public java.lang.String getWelcomeBuffer()

executeCmdWithTimeOut

public java.lang.String executeCmdWithTimeOut(java.lang.String cmd)
                                       throws java.lang.Exception
Runs the specified command until completion or timeout. A timeout stops the command run but does not throw an exception.

Parameters:
cmd - The command to run
Returns:
The console output
Throws:
java.lang.Exception - on connection error

executeCmd

public java.lang.String executeCmd(java.lang.String cmd)
                            throws java.lang.Exception
Runs the specified command.

Parameters:
cmd - The command to run
Returns:
The console output
Throws:
java.lang.Exception - on connection error or timeout

executeCmd

public java.lang.String executeCmd(java.lang.String cmd,
                                   boolean readUntilTimeout)
                            throws java.lang.Exception
Runs the specified command until completion or timeout.

Parameters:
cmd - The command to run
readUntilTimeout - The effect of this parameter is implementation dependent
For an NTCMD client, if readUntilTimeout is true, the command fails if the default timeout is reached. If false, the command runs to completion or until it throws a fatal error.
For an SSH client, if readUntilTimeout true, no response is returned to the client and the command is canceled on timeout. If false, the method returns the console output.
Telnet clients ignore this argument.
Returns:
The console output
Throws:
java.lang.Exception

executeCmd

public java.lang.String executeCmd(java.lang.String cmd,
                                   int cmdTimeout)
                            throws java.lang.Exception
Runs the specified command until completion or the specified timeout.

Parameters:
cmd - The command to run
cmdTimeout - The timeout in milliseconds
Returns:
The console output
Throws:
java.lang.Exception

executeCmd

public java.lang.String executeCmd(java.lang.String cmd,
                                   int cmdTimeout,
                                   boolean readUntilTimeout)
                            throws java.lang.Exception
Runs the specified command until completion or the specified timeout.

Parameters:
cmd - The command to run
cmdTimeout - The timeout in milliseconds
readUntilTimeout - If true, the command fails if the default timeout is reached. If false, the command runs to completion or until it throws a fatal error.
Returns:
The console output
Throws:
java.lang.Exception

getLastCommandOutputBytes

public byte[] getLastCommandOutputBytes()
                                 throws java.lang.Exception
Throws:
java.lang.Exception

setCharset

public void setCharset(java.nio.charset.Charset charset)

getServerPort

public java.lang.String getServerPort()
                               throws java.lang.Exception
Returns the server port from the protocol properties.

Returns:
The port number
Throws:
java.lang.Exception

canCopyFile

public boolean canCopyFile()

getFile

public java.lang.String getFile(java.lang.String remoteFileName,
                                java.lang.String remoteShareName)
                         throws java.lang.Exception
Throws:
java.lang.Exception

putFile

public java.lang.String putFile(java.lang.String localFileName,
                                java.lang.String remoteShareName)
                         throws java.lang.Exception
Throws:
java.lang.Exception

deleteFile

public boolean deleteFile(java.lang.String remoteFileName,
                          java.lang.String remoteShareName)
                   throws java.lang.Exception
Throws:
java.lang.Exception

getMaxCommandLength

public int getMaxCommandLength()
Returns the maximum length (bytes) of a command that can be sent to this client.


setMaxCommandLength

public void setMaxCommandLength(int maxCommandLength)
Sets the maximum length (bytes) of a command that can be sent to this client.



Documentation Feedback
Copyright 2010 Hewlett-Packard Development Company, L.P.