The product uses a script that is written in bean shell or JavaScript for the Run Telnet Script operator Inline Script field. The script uses the conn object, which exposes the following APIs:
void send (String str, boolean log) throws Exception
This method sends data to the remote host.
Defines the data to send to the remote host.
Exposes or hides the data sent to remote host in the CA Process Automation logs.
To debug, follow the interaction between the operator and the remote host. Set the following code in the <install_dir>/server/conf/log4j.xml file:
<category name="com.company.c2o.servicegroup.netutils">
<priority value="DEBUG" /> </category>
Also, set the CA Process Automation log file (c2o.log) to accept the DEBUG statements in log4j.xml.
When you set the debug level, the Command Execution operator category starts logging to the CA Process Automation log file (c2o.log) at the DEBUG level. The CA Process Automation logs expose any data sent to the remote host through send or sendLine.
True: Logs the String str value when logging at the DEBUG level.
False: Does not log the String str value.
Note: c2o.log is the CA Process Automation log file, not the process logs. The operators do not write messages to the process log.
This method has no return values. The product generates an exception if the API cannot write the data to the remote host.
public void sendLine (String str, boolean log) throws Exception
This method appends a new line character to the data and sends it to the remote host. To force the remote host to start running the command that is sent in the parameter, use this method.
This method has the same parameters and values as void send (String str, boolean log) throws Exception.
void send (String str) throws Exception
This method is equivalent to Send (String str, true).
void sendLine (String str) throws Exception
This method is equivalent to SendLine (String str, true).
public boolean waitFor(String pattern, int timeout) throws Exception
This method reads the output from the remote host and stops when either of the following results occurs:
The product stores the output from the remote host by each call to the waitFor method in a buffer accessible through the getLastOutput() method. Each waitFor call overrides the buffer content from the previous call.
The next waitFor call starts reading the output from where the previous waitFor call stopped reading. This is relevant when you use the method with getLastOutput.(). For example, if a waitFor call does not match the entire command output, the next call can contain the remaining output from the previous command.
Important! To avoid mixing the previous command output with the current command output, call waitFor after each sendLine call.
The Telnet script and SSH script operators use different mechanisms to read data from the remote host:
Parameters include:
Defines a regular expression to match against the data that the product reads from the remote host. Typically, this pattern matches any data up to the next prompt (for example, ".*[$]"). Because you can match (and retrieve) the command output data (including new lines up to the next prompt), start the pattern with .*.
Note: The method matches the entire data read (during this waitFor call) against the pattern. The method does not match the pattern as a substring of the data read. Also, a dot ( . ) can match a new line terminator (it can be used to match multiline reply data).
Defines the interval (in seconds) during which to read data from the remote host and match it against the pattern.
Returns are Boolean:
The data read before the timeout expired matches the pattern.
The data read before the timeout expired does not match the pattern.
Note: The method returns a value as soon as it matches the pattern or the timeout expires.
The product generates an exception in the following cases:
public String getLastOutput()
This method returns the content of the buffer where the last waitFor call saved the data that it read from the remote host. This data does not always match the waitFor pattern. The buffer stores whatever the most recent waitFor call read, whether waitFor returned true or false.
This method has no parameters.
This method does not generate exceptions.
|
Copyright © 2014 CA.
All rights reserved.
|
|