Executing NSH commands or scripts against multiple targets

This topic was edited by a BMC Contributor and has not been approved.  More information.

BMC Server Automation provides a pair of commands, runscript and runcmd, that allow users to execute Network Shell (NSH) commands or scripts against multiple systems in parallel. These commands are equivalent to running the cd command and switching to a number of remote systems and executing commands in the remote context. These commands are not intended to replace nexec, since they cannot execute a local command on a remote system. You can only use commands found in remote_cmds and NSH commands. If you attempt to execute a local command, you will either get inappropriate (out of context) results or a command not found error.

runcmd

The runcmd command is used to execute a single command across multiple machines. As stated earlier, this command does not emulate the nexec functionality. Rather, it is used to execute NSH commands and remote commands. For a full description of the command and usage information, see the man pages. One runcmd option worth mentioning is the '-p' switch. When runcmd is executed with the '-p' switch, the commands executed via runcmd are executed in parallel. The number of parallel processes is controlled by the number placed after the '-p' switch. Parallelism is accomplished by forking multiple subshells.

runscript

The runscript command is equivalent to the runcmd command. The only difference is that it is used to execute NSH scripts across multiple systems. All the options available to runcmd are also available in runscript.

When writing an NSH script to be executed via runscript you must keep in mind the context of execution. The script is executed in the context of the remote host but any commands that are not remote (found in the remote_cmds file) or nsh commands are executed in the context of the local system.

A script executed via runscript has the same context as that of commands run from a local nsh session against a remote server. If one were to execute 'script1' via scriptutil against 'host1', the equivalent command sequence from an interactive NSH session is:


Cd //host1/
//@/directory/script1

Therefore, any non-remote or nsh commands must be executed using the nexec command with the '-e' switch to execute them on and against the remote system. Using the absolute path is only necessary if the command is not in the default path found in NSH's $PATH variable.


nexec -e /Path/to/command/script1
Was this page helpful? Yes No Submitting... Thank you

Comments