Unsupported content

 

This version of the documentation is no longer supported. However, the documentation is available for your convenience. You will not be able to leave comments.

Creating and running a job that uses the NSH script

To run your script, you must create and run an NSH Script Job.

  1. From within the BMC Server Automation Console, create a Jobs subfolder in which you plan to store your NSH Script Job. (Right-click the Jobs folder and select New > Job Folder.)
  2. When the New Job Folder wizard appears, fill in the name of the new subfolder. In this example, the name of this folder is MyScriptJobs.
  3. Click Next repeatedly to proceed through the wizard panels, accepting all defaults.
  4. Click Finish to exit the wizard.

Now that you have created the MyScriptJobs folder, you can create and run the job by using the BLCLI or the BMC Server Automation Console:

Creating and running a job by using the BLCLI

  1. Start NSH, authenticate, and connect to the Application Server as described in Setting up to run BLCLI commands in an NSH shell.
  2. Create the job by using the NSHScriptJob createNSHScriptJobcommand:

    MY_NSH_PROMPT% blcli_execute NSHScriptJob createNSHScriptJob "/MyScriptJobs" "SetServerPropertyValueJob1" "SetServerPropertyValueJob1" "/MySubFolder" "SetServerPropertyValue2" "myAppServer" 1

    The syntax for this command is described in the NSHScriptJob reference chapter of this help system. You are basically specifying the location to store the job (/MyScriptJobs), a name and description for the job, the location and name of the script to run, and the Application Server against which you want to run the script.
    The command returns the DBKey of the newly created job (DBKey:SJobModelKeyImpl:2000120-1-2003508):
    DBKey:SJobModelKeyImpl:2000120-1-2003508MY_NSH_PROMPT%

  3. When you want to store what was returned from the most recent blcli_execute command, use the blcli_storeenv command. In this case, store the DBKey of the job in the JOB_KEY variable:
    MY_NSH_PROMPT% blcli_storeenv JOB_KEY
  4. Run the job, using the NSHScriptJob executeJobAndWait command:
    MY_NSH_PROMPT% blcli_execute NSHScriptJob executeJobAndWait $JOB_KEY
    The command returns the run key of the job you just ran:
    DBKey:SJobRunKeyImpl:2000405MY_NSH_PROMPT%
  5. Store the run key in the RUN_KEY variable:
    MY_NSH_PROMPT% blcli_storeenv RUN_KEY.
  6. Later, you can examine the results of the job. To examine the results, you need the run ID for the job. Use the JobRun jobRunKeyToJobRunId command to get the run ID:
    MY_NSH_PROMPT% blcli_execute JobRun jobRunKeyToJobRunId $RUN_KEY
    The command returns the run ID — in this case 2000405.
    2000405MY_NSH_PROMPT%
  7. Store the run ID in the RUN_ID variable:
    MY_NSH_PROMPT% blcli_storeenv RUN_ID
  8. Now that you have the RUN_ID, you can examine the results of the job, by using the Utility exportNSHScriptRun command which exports the results into a CSV file:
    MY_NSH_PROMPT% blcli_execute Utility exportNSHScriptRun $RUN_ID "C:\temp\myResults.csv"
    This command returns void.
    voidMY_NSH_PROMPT%
    The myResults.csv file looks something like this:

Where to go from here

Now that you have verified that the job completed successfully, check that the script itself accomplished its goals. This is described in Testing the script results.

Creating and running a job by using the BMC Server Automation Console

  1. Expand the Depot folder and navigate to the subfolder where you added your script. In this example, the script is located here:
    MySubFolder/SetServerPropertyValue
  2. Right-click the script (SetServerPropertyValue) and select NSH Script Job.
  3. When the NSH Script Job wizard appears, fill in the values as as follows:
    • Name: SetServerPropertyValueJob
    • Save in: Click Browse to navigate to the new Jobs subfolder you just created:
      Jobs/MyScriptJobs
    • Accept all the other defaults.
  4. Click Next to advance to the second panel in the wizard.
    This panel lets you specify the target for the job. Because this script needs to list all the enrolled servers in your system, you specify the Application Server as the target. This is the reason that you needed to add the Application Server as an enrolled server at the beginning of this tutorial (see Before you begin).
  5. To specify the Application Server as the target:
    1. In the Available Servers column, expand the Servers node and navigate to the Application Server.
    2. Highlight the Application Server (in this example it is called MyAppServer).
    3. Click the right-arrow button to move the Application Server into the Selected Servers column.
    4. Click Next to advance to the third panel in the wizard (Parameters). Leave this panel blank.
    5. Click Next to advance to the fourth panel in the wizard (Default Notifications). Leave this panel blank.
  6. Click Next to advance to the fifth panel in the wizard (Schedules).
  7. Click Execute job now.
  8. Click Next to advance to the sixth panel in the wizard (Properties). Accept the defaults.
  9. Click Next to advance to the seventh panel in the wizard (Permissions). Accept the defaults.
  10. Click Finish. The job starts running. While it is running, you can see an indication of its progress in the Tasks in Progress panel, as shown in the following figure.
    After the job completes, you can check the results as follows:
    1. Navigate to the job:
      Jobs/MyScriptJobs/SetServerPropertyValueJob
    2. Right-click the job and select Show Results.
      Results for this job appear in the upper right panel. Results include start and end times, whether or not the job completed successfully, and other details.

Where to go from here.

Now that you have verified that the job completed successfully, check that the script itself accomplished its goals. This is described in Testing the script results.

Was this page helpful? Yes No Submitting... Thank you

Comments