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.

 
Set <Variable> <Value>

 

Variable The name of the variable that is set with the value.
Value The value to set.

 

 

Example 1:

Init=(script)set verifyLogon 0;

In this example, the variable verifyLogon is set with the value 0.

 

 

Example 2:

SetSolarisVerifySwitch=(script)set whoami /usr/ucb/whoami;

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:

ExtraPassStartSessionWithSSHKeys=(script)set ssh_Key_parameter "pmextrapass1"; set useSSHKey "1"

In this example, the two variables are set in a single command:

  • The ssh_Key_parameter is set to pmextrapass1, so when a connection is established the key is taken from the logon account
  • The useSSHKey is set to 1, so that when the connection is established, it is done using an SSH key and not a password

Close

Close the connection to the target.

 

Example:

logout=(script)close

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.

 
append <Variable> <Value>

 

Variable

The name of the variable to which the value is appended.

Value

The value to append.

 

 

Example:

CreateMutex=(script)set tmp "<address>";append tmp "-";append tmp "$fileDirectory"

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:

  • The address, taken from target account
  • The const “-“
  • The path to the file taken from the fileDirectory variable

String map

Replaces sub-strings in a string based on the key-value pairs in mapping.

 
String map ?-nocase? {<Mapping>} <String>

 

-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:

SetDynamicParam=(script) set mapped_command [string map -nocase {"%username%" "<username>"} "<command>"];

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:

ReplaceSpecial=(script)set mapped_name [string map {\\ - / - : - * - \< - \> -} $name]

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.

 
Set <Variable> <Value>

 

String The input string for which the length is returned.

 

 

Example:

InputLength =(script) set inputLength [string length <input>]

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 index <String> <CharIndex>

 

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:

FirstChar =(script) set firstChar [string index <input> 0]

In this example, the variable firstChar is set with the value of the first character of the input parameter.

 

 

Example 2:

Ten =(script) set ten [string index <input> 9]

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:

Zero =(script) set zero int(0.0);

In this example, the variable zero is set with the number 0.

 

 

Example 2:

Zero =(script) set zero int(0.25); In this example, the variable zero is set with the number 0.

 

 

Example 3:

Wait =(script) after <SleepTime> * 1000;

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:

RandNumber =(script) set randNumber expr {int(8.0*rand()+1)};

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.

 
incr <varName> ?<increment>?

 

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:

Counter =(script) incr $counter

In this example, the value of the Counter variable is increased by 1.

 

 

Example 2:

Counter =(script) incr $counter <input>

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.

 
after <Arg> ?<Script>?

 

Arg The number of milliseconds to wait before executing the command.
Script The command to run after the given time.

 

 

Example 1:

Wait =(script) after <SleepTime> * 1000;

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.

 
log <message>

 

Message The string to be printed to the logs. The string can contain free text, variables, and parameters.

 

 

Example 1:

log "Username: " <username>

In this example, the username parameter from the account will be printed to the log with the prefix "Username: ".

 

 

Example 1:

log "Use SSH Key : " useSSHKey

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: ".