This documentation supports the 21.05 (12.2) version of BMC Discovery.To view an earlier version of the product, select the version from the Product version menu.

discovery.runCommand


discovery.runCommand(target, command, restrict_paths, dialect)

Returns a DiscoveredCommandResult node containing the result of running the specified command.

The function takes the following parameters:

  • target, where target is:
    • a node used to identify the discovery target; one of the following nodes:
      • Host
      • DiscoveryAccess
      • DiscoveredDirectoryEntry
      • DiscoveredFQDN
      • DiscoveredHBA
      • DiscoveredListeningPort
      • DiscoveredNetworkConnection
      • DiscoveredNetworkInterface
      • DiscoveredProcess
      • DiscoveredSNMPRow
      • DiscoveredWMI
      • SQLResultRow
      • DirectoryListing
      • DiscoveredPackages
      • DiscoveredSNMPTable
      • DiscoveredWMIQuery
      • FQDNList
      • HBAInfoList
      • IntegrationResult
      • InterfaceList
      • NetworkConnectionList
      • ProcessList
      • DeviceInfo
      • DiscoveredCommandResult
      • DiscoveredFile
      • DiscoveredPatches
      • DiscoveredRegistryValue
      • DiscoveredSNMP
      • HostInfo
    • Or a data source against which the request is performed. See also, discovery-dataSource.
  • command  is the command to run. 
  • restrict_paths is a string or list of strings that are checked against the any path restrictions that are configured. The system prevents execution of any commands accessed using matching paths. The restrict_paths parameter enables you to validate that paths to commands determined in your pattern are not restricted, so your pattern is free to use those commands.
  • dialect  is the dialect of command to run, overriding the default dialect, which is determined by the type of shell you are using.  If dialect  is not specified, the default is used. The following dialects are supported:
    • /bin/sh— the "normal" shell used by UNIX and Linux operating systems. Includes bash, zsh, and so on.
    • CMD.EXE—The Windows command prompt. This is the default dialect used whenever encounters a shell on a Windows host.
    • DCL—The VMS environment Digital Command Language prompt.
    • /bin/hmcbash—The IBM Hardware Management Console (HMC) prompt.
    • powershell.exe—Windows PowerShell prompt. There is a dedicated discovery-runPowerShell function that we recommend rather than using a dialect.

The following code examples shows discovery.runCommand being used to determine the publisher of a Java virtual machine. This comes from the TKU Java VM pattern.

publisher_command := '%javacmd_path% -version';

// Run java -version and extract the publisher
ran_pub_cmd := discovery.runCommand(host, publisher_command);
...

...
if ran_pub_cmd then
    log.debug("Publisher command output: %ran_pub_cmd.result%");
    cmd_publisher := regex.extract(ran_pub_cmd.result,
                                   regex'(?i)(hotspot|gnu|ibm|bea|sun)', raw'\1');
end if;

Possible post-processing required on UNIX/Linux hosts

When a pattern executes a command on a UNIX/Linux host, the result returned can contain control characters used to display colors and other formatting. The pattern should not rely on being able to use the result without some additional processing such as regular expression matching and extraction.

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*