Remote Monitoring & Management Help

Parse Command Line Argument

When configuring the Monitoring Check or Automated Task (Windows or Mac), it is possible to pass arguments to the script via the Command Line option of the relevant dialog.

These arguments may be used to control the behavior of script or pass the script's target (for example the actions to perform or services to restart).

This has the following advantages over hard-coding the behavior and target in the script as common code can be reused - for example connect to the service manager as well as reducing the number of scripts required thus improving the maintainability of your script library, for example an individual script is not required per service.

The method used to access these arguments varies per scripting language and the following example illustrates the arguments used for DOS Batch, BASH, Perl, PHP, and VBScript.

Argument

Notes

DOS Batch

%1, %2 etc

%0 is name of script

Linux shell scripts

(BASH)

$1, $2 etc

$0 is name of script

Dynamic languages

(Perl, PHP)

$argc (count) and @argv (array)

VBScript

WScript.Arguments.Count

Method gives number of arguments

WScript.Arguments(0) is first argument etc

When the Agent runs the script two arguments are always appended to the command line (for debug) and the -logfile logname can be ignored.

Improved Script argument handling (Windows)

Please be aware that Windows Monitoring Agents 9.12.2 and 9.13.6 introduced improvements to the handling of the script arguments entered in the Script Parameters, Command Line field of the custom Script Check (9.12.2) and Automated Task (9.13.6). With these improvements any specified arguments are passed to the script exactly as they would be if entered directly on the device itself.

What do you want to do?