com.hp.ucmdb.discovery.library.clients.shell
Class NTCMDClient
java.lang.Object
com.hp.ucmdb.discovery.library.clients.BaseClient
com.hp.ucmdb.discovery.library.clients.shell.ShellClient
com.hp.ucmdb.discovery.library.clients.shell.NTCMDClient
public class NTCMDClient
- extends ShellClient
NTCMDClient
provides APIs for executing shell commands on hosts running a Windows OS.
For a creation example, see ShellClient
.
Properties that can be redefined for NTCMDClient:
- Output matching (matchers)
The matchers list property (java.util.List
) specified by
AgentConstants.PROP_AGENT_OUTPUT_MATCHERS
is the list of strings
that indicate end-of-output to the client. The output is considered finished when
any one of the matchers is encountered. Methods of this class do not return
any information about which matcher was encountered.
In session mode, by default the client changes the prompt of
the remote shell to a known string and adds it to the matchers list. This
means that completion of regular shell commands are correctly identified and
control returned to the shell. It is rare, but this will fail if the prompt
string appears in the output.
Additional matchers must be defined for end-of-output where another process is launched
from the remote shell (for example, Websphere MQ console)
and that process is itself an interactive process that doesn't return to the
shell after each command.
If no matchers are found, commands return after the timeout.
- XCmd flags
XCmd provides command execution options, for example, copy a file to the remote host
before executing, leave the service running on the remote, and others. These
flags are passed to xcmd when it starts. To use these flags in
session mode set the property
AgentConstants.PROP_NTCMD_AGENT_START_FLAGS
and put a
java.util.List
of java.util.String
that reflect
the flags as they would appear in the command line.
- All Protocol properties can be redefined in properties when
creating the client.
In addition to executing a remote shell command, the NTCMDClient
can copy a file to the remote host,
execute it on the remote, and bring back its console output. Here is a Jython code
example for a coping utility that obtains disk information on remote machine:
props = Properties()
# Next two lines specify the absolute path where utility file exists. By default, this code points
# to $DiscoveryProbe_INSATALLDIRroot\lib\collectors\probeManager\discoveryResources\, but any folder can be specified.
agent_root_dir=CollectorsParameters.BASE_PROBE_MGR_DIR
agent_ext_dir = agent_root_dir + CollectorsParameters.getDiscoveryResourceFolder() + '\\diskinfo.exe'
props.setProperty(AgentConstants.PROP_NTCMD_AGENT_START_FLAGS, '/C:' + agent_ext_dir + ' /D');
# During client creation and connection, this file will be copied to ADMIN$\\System32\ on the remote computer.
# By default, this directory is in the system PATH.
xcmd = Framework.getClientFactory(ClientsConsts.NTCMD_PROTOCOL_NAME).createClient(props)
# Execute the command
buffer = xcmd.executeCmd('diskinfo')
- See Also:
ShellClient
,
ClientFactory
,
com.hp.ucmdb.discovery.probe.clients.ClientsConsts
Constructor Summary |
NTCMDClient(ClientsFrameworkImpl framework,
java.util.Properties props)
|
Method Summary |
boolean |
canCopyFile()
Checks whether files can be copied. |
boolean |
deleteFile(java.lang.String remoteFileName,
java.lang.String remoteShareName)
Deletes the specified file. |
java.lang.String |
getFile(java.lang.String remoteFileName,
java.lang.String remoteShareName)
Copies a file from the remote host. |
java.lang.String |
putFile(java.lang.String localFileName,
java.lang.String remoteShareName)
Copies a local file to the remote host. |
Methods inherited from class com.hp.ucmdb.discovery.library.clients.shell.ShellClient |
executeCmd, executeCmd, executeCmd, executeCmd, executeCmdWithTimeOut, getLastCommandOutputBytes, getMaxCommandLength, getServerPort, getWelcomeBuffer, setCharset, setMaxCommandLength |
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 |
NTCMDClient
public NTCMDClient(ClientsFrameworkImpl framework,
java.util.Properties props)
throws java.lang.Exception
- Throws:
java.lang.Exception
canCopyFile
public boolean canCopyFile()
- Checks whether files can be copied.
- Overrides:
canCopyFile
in class ShellClient
- Returns:
- true if the client can copy files to the remote machine
deleteFile
public boolean deleteFile(java.lang.String remoteFileName,
java.lang.String remoteShareName)
throws java.lang.Exception
- Deletes the specified file.
- Overrides:
deleteFile
in class ShellClient
- Parameters:
remoteFileName
- The name of the file on remote host to deleteremoteShareName
- The path to the shared folder containing the file to delete
- Returns:
- true if deletion successful
- Throws:
java.lang.Exception
getFile
public java.lang.String getFile(java.lang.String remoteFileName,
java.lang.String remoteShareName)
throws java.lang.Exception
- Copies a file from the remote host.
- Overrides:
getFile
in class ShellClient
- Parameters:
remoteFileName
- The name of the file to copyremoteShareName
- The path to the shared folder containing the file to copy
- Returns:
- The local name of the copied file
- Throws:
java.lang.Exception
putFile
public java.lang.String putFile(java.lang.String localFileName,
java.lang.String remoteShareName)
throws java.lang.Exception
- Copies a local file to the remote host.
- Overrides:
putFile
in class ShellClient
- Parameters:
localFileName
- The fully qualified local path and name of the file to copyremoteShareName
- The path to the shared folder into which to copy the file
- Returns:
- The name of the copied file on the remote machine
- Throws:
java.lang.Exception
Documentation Feedback
Copyright 2010 Hewlett-Packard Development Company, L.P.