Tcl commands
You can use Tcl commands in TPC. Use these commands for working with variables, manipulating strings, arithmetic operations, and more.
This section describes how to use the most common commands in TPC.
For all Tcl commands, see Tcl commands.
Variable commands
Set
Read and write variables.
|
Variable | The name of the variable that is set with the value. |
Value | The value to set. |
Example 1:
In this example, the variable verifyLogon is set with the value 0. |
Example 2:
In this example, the variable whoami is set to /usr/ucb/whoami;, which is the location of the whoami command on Solaris. This can be used to run the relvant command for different Linux\Unix targets. For details, see TPC variables. |
Example 3:
In this example, the two variables are set in a single command:
|
Close
Close the connection to the target.
Example:
In this example, the close command is used. When reaching this state, TPC closes the current connection to the target. |
String commands
Append
Append to variable.
|
Variable |
The name of the variable to which the value is appended. |
Value |
The value to append. |
Example:
In this example, the variable tmp is set with the value to be used when creating a mutex. This value is defined by concatenating three sections:
|
String map
Replaces sub-strings in a string based on the key-value pairs in mapping.
|
-nocase |
Optional indication that the mapping should be case insensitive. |
Mapping |
A list of pairs. Each first element in a pair will be replaced by the second element if found in the string. |
String |
The input string that is searched. |
Example 1:
In this example, all the instances of %username% in the parameter command are replaced with the value of the username from the target account. -nocase is used so that the match will be case-insensitive and will also replace instances like %Username% and %USERNAME%. |
Example 2:
In this example, a list of special characters are replaced with the ‘-‘ character before the string can be used. |
String length
Returns the number of characters in a string.
|
String | The input string for which the length is returned. |
Example:
In this example, the variable inputLength is set with the length of the input parameter from the target account. This can be used to validate that the input parameter does not contain a long string, and fail the plugin before sending it to the target. |
String Index
Returns the CharIndex character of the string argument.
If the string is too short, an empty string (“”) is returned, and no error will be invoked.
|
String | The input string from which the charter will be taken. |
CharIndex |
The index from which to take the character. A CharIndex of 0 corresponds to the first character of the string. |
Example 1:
In this example, the variable firstChar is set with the value of the first character of the input parameter. |
Example 2:
In this example, the variable ten is set with the value of the 10th character of the input parameter (since CharIndex begins at 0). |
Numeric commands
int
The integer part of the argument number.
int(<Arg>) |
Arg | The input number from which the integer value will be taken. |
Example 1:
In this example, the variable zero is set with the number 0. |
Example 2:
|
Example 3:
In this example, the plugin waits for the length of time defined in the SleepTime argument before continuing. |
rand
Produces a random number between 0 and 1.
rand() |
Example:
In this example, the variable randNumber is set with a random number in the range of 1-8. |
incr
Increment the value of a variable.
|
varName | The name of the value that is incremented. |
increment | The increment amount. If a value is no provided, the increment will be by 1. |
Example 1:
In this example, the value of the Counter variable is increased by 1. |
Example 2:
In this example, the value of the Counter variable is increased by the value in the input parameter. |
Sleep commands
After
Execute a command after a time delay.
|
Arg | The number of milliseconds to wait before executing the command. |
Script | The command to run after the given time. |
Example 1:
In this example, the plugin waits for the length of time defined in the SleepTime argument before continuing. |
Log commands
Log
Print information to the log file for debugging.
|
Message | The string to be printed to the logs. The string can contain free text, variables, and parameters. |
Example 1:
In this example, the username parameter from the account will be printed to the log with the prefix "Username: ". |
Example 1:
In this example, the local variable, useSSHKey, which was set earlier in the plugin run, will be printed to the log with the prefix "Use SSH Key: ". |