Agent Execute

Function

Execute a program on the target system (Windows only)

Alarming

Exit code, Running time

Agent Execute detail

Agent Execute parameters

Parameter

Description

Program path

Executable program including its absolute path. This path or specific executable must be allowed in the Run Programs section of the remote WinAgent configuration.

Command line arg.

Command line arguments for the executable.

Timeout

The executable will be terminated after the timeout period, if still running. If set, this timeout overrides the default timeout in the remote WinAgent configuration (Default process timeout).

Execute one instance only

Only one instance of the executable is allowed if checked. If the executable is already on the running program list of the target system, it will not be started again.

Hide window during execution

If this checkbox is set, the WinAgent hides the windows of the executed application.

Suppress running time

If this checkbox is set, the running time of each check is not saved to the database and its value is no longer visible in the values section. Its value is also no longer available for use in alarm limit specifications.

The Tags dropdown list allows entering pre-defined variables into the fields above, e.g. $NAME$ for the name of the job.

Agent Execute values and alarm limits

Value / Alarm limit

Description

Exit code

The exit code returned by the executable. Usually an exit code of 0 means there were no errors during the execution, however, the exit code depends on the executable.

Running time

The duration of the remote program execution (in s). This value and alarm limit is only available if the Suppress running time parameter is not enabled.

Error code

Generic job error code (see section Job error codes)

Agent Execute examples

Example 1 - Issue a reboot remotely

This example uses the shutdown.exe system command with the /r argument to issue a reboot of the remote machine.

This requires the command or its parent directory to be allowed in the remote WinAgent configuration in the Run programs tab:

Output 1

Example 2 - Check if the service w32time is running using the wmic command on the remote machine

This runs the following command and checks if the w32time service is running on the remote machine:

Program path

C:\Windows\system32\cmd.exe

Command line arg.

/C FOR /F %G IN ('wmic service w32time get state /value ^| findstr "State=Running"') Do exit /B 0

The cmd.exe executable must also be allowed in the remote WinAgent configuration in the Run programs tab (see above).

This allows to check a service status on remote machines running e.g. Windows 2000, which is not supported for the Agent Service job plugin.

Output 2

If the service is running, the exit code is = 0, if it’s stopped or not available the exit code is = 1.

Example 3 - Ping a server from the Windows host using PowerShell

This job will ping server server1 from the Windows system and return exit code 0 in case of success or 1 if it fails.


Program path

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe

Command line arg.

if (test-connection server1 -Count 2 -Quiet) {exit 0} else {exit 1}

The PowerShell.exe  must also be allowed in the remote WinAgent configuration in the Run programs tab (see above).