scriptutil: The Slightly Odd Duck
This topic was created by a BMC Contributor and has not been approved. More information.
This topic describes the scriptutil utility, which enables the execution of non-NSH scripts against remote targets. The topic includes the following sections:
For a video with an example of how to use scriptutil to include a non-NSH script in a compliance policy, see Examples of editing templates and compliance rules.
Overview of scriptutil
Scriptutil was written by Thomas Kraus (the creator of NSH) to allow for the execution of non-NSH scripts against remote targets. The beauty of scriptutil is that you can create a single execution command for a variety of Operating Systems. This can be very helpful in creating consistent script results across multiple platforms using multiple scripting languages.
Scriptutil does not quite fit in with the other script execution commands because it is intended to execute scripts that are not NSH scripts. It offers functionality similar to runscript in that it allows scripts in the local file system to be executed on remote servers. However, it does not allow for parallelization and the scripts it executes generally have no understanding of NSH. This command is most often used to execute BladeLogic extended objects, but it can be used as a general remote script execution utility.
Scriptutil is a relatively straight-forward utility. It copies any shell script (with a few requirements to be discussed soon) to a remote server (via NSH into /tmp by default) and executes the command on the remote server as a local command. The output is returned to scriptutil and printed to stdout on your local shell session. The shell these scripts execute in must be one installed in the remote server. So, if a script calls a PDKSH shell, then PDKSH must be found in the location designated by the script's shell designator (first line of shell, starting with #!) All arguments to the script must be passed using the '-x' operator. To see the full usage of the command, please check out the man page.
There are two requirements for executing a shell script via scriptutil. First, all scripts to be handled by scriptutil must be located in the BL_INSTALL_DIR/share/sensors directory. Second, all scripts must have an XML header in a particular format. Here is an example of an acceptable header:
#!/usr/bin/ksh #<name> antivirus_check.SunOS #<desc> Determine whether Anti-Virus software is installed and up-to-date. #<type> KSH Script (Extended Object) #<sci> Unknown #<owner> Thomas Kraus #<doc> NAME #<doc> antivirus_check #<doc> SYNTAX #<doc> antivirus_check #<doc> DIAGNOSTICS #<doc> Exit code 0 if successful #<doc> Exit code 0 if unsuccessful #<doc> DESCRIPTION #<doc> Determine whether Anti-Virus software is installed and up-to-date.
One very handy feature of scriptutil is its ability to understand whether a script is OS-specific or not. If a certain type of script is needed for multiple operating systems, you do not have to write a single long script that understands the differences in commands/options on each operating system. You can write scripts specific to each OS (much easier) and have scriptutil determine which script should be sent to which operating system. You only need to call scriptutil once and not worry about whether the right script goes to the right systems.
How it Works
Scriptutil determines which version of the script should executed a certain OS by looking at its extension. You just need to have the scripts be named script_name.OS_TYPE. So, if you have a set of scripts called "pwd_expiration_check" for all BladeLogic supported operating systems, you would rename them:
- Windows: pwd_expiration_check.WINNT
- Linux: pwd_expiration_check.Linux
- SunOS/Solaris: pwd_expiration_check.SunOS
- AIX: pwd_expiration_check.AIX
- HPUX: pwd_expiration_check.HP-UX
To execute this set of scripts on the various OS types, you would only have to execute a single scriptutil command:
scriptutil -h win1 sun1 aix1 hpux1 -s pwd_expiration_check
If you have a script that executes properly against all operating systems, then you would not need to have a filename extension signifying the operating system. If scriptutil sees a script without the OS extension, it assumes the script can be run against all operating systems.
One last feature of scriptutil is the script index function. From the XML headers mentioned above, scriptutil will list the name of all commands in the sensors directory and their descriptions. You just need to use the '-l' extension. For more info, see the man pages.