Important

   

This space contains documentation for TrueSight Server Automation 8.9.03 and the later service packs for 8.9. For earlier releases, see BMC Server Automation 8.9.

Sample NSH script - SetServerPropertyValue.nsh

This example script sets a certain property to a certain value on all the servers that are enrolled in your BMC Server Automation system. This script will be run from within an NSH Script Job.

Before you begin

  • Enroll the Application Server as a managed server in the BMC Server Automation system.
    From within the BMC Server Automation Console, expand the Servers folder, right click a server group, and select Add Server. Then fill in the name or IP address of the Application Server.

Adding a new server property

To add a new server property, do either of the following:

Adding a new server property by using the BLCLI

  1. Open a command prompt and start NSH by typing nsh.
    C:\some_directory>nsh
    The prompt changes to your NSH prompt.
    MY_NSH_PROMPT%
  2. Assuming that you have set up authentication, (see Setting up authentication), use the blcli_setoptioncommand to specify the service profile and role that you want to use.

    MY_NSH_PROMPT% blcli_setoption serviceProfileName myServiceProfile
    MY_NSH_PROMPT% blcli_setoption roleName BLAdmins
    
  3. Populate the credentials cache.

    MY_NSH_PROMPT% blcred cred -acquire -profile myServiceProfile
      -username testUser -password testPassword
    Authentication succeeded: acquired session credential
    
  4. Connect to the Application Server.
    MY_NSH_PROMPT% blcli_connect
  5. Use the PropertyClass addProperty command to add a new Server
    property called MY_PROPERTY.

    MY_NSH_PROMPT% blcli_execute PropertyClass addProperty "Class://SystemObject/Server" "MY_PROPERTY" "My Property" "Primitive:/String" true false "initialDefaultValue"

    The PropertyClass addProperty command returns void.
    MY_NSH_PROMPT% void

Adding a new server property by using the BMC Server Automation Console

  1. Start the BMC Server Automation Console.
  2. Choose Configuration > Property Dictionary View.
  3. Expand Built-in Property Classes.
  4. Scroll down to the Server property class and then click the Server property class.
  5. Click Add new property .
  6. Fill in the Add Property window as follows. Be sure to call the new property MY_PROPERTY and accept all defaults.

Examining SetServerPropertyValue.nsh

01 blcli_connect
02 blcli_execute Server listAllServers
03 blcli_storeenv SERVERS
04
05 for SERVER in ${SERVERS}
06 do
07 blcli_execute Server setPropertyValueByName ${SERVER} MY_PROPERTY "some Value"
08 done 

Line 1: Connect to the Application Server, using the blcli_connect command. (For more information about this command, see blcli_connect.)

Why no authentication? In the previous tutorial (Learning how to run your first BLCLI command), you performed authentication by using the -v option to specify a service profile and the -r command to specify a role. In this tutorial, the SetServerPropertyValue.nsh script will be run within an NSH Script Job, and therefore will inherit authentication from the Application Server.

For more advanced information on authentication in different scripting environments, see Additional authentication details - Running scripts from different places.

Line 2: Use blcli_execute to execute the command:

Server listAllServers

This command lists all the servers that are enrolled in the BMC Server Automation system, and does not take any arguments. (For more information about this command, see blcli_execute.)

You can store the output from this command (the list of servers) in an environment variable, as explained in the next line.

Line 3: Use the blcli_storeenv command to store the output from the previous blcli_execute command in an environment variable. In this case, the script stores the list of enrolled servers in the SERVERS variable.

Lines 5-7: Run the Server setPropertyValueByName command against each SERVER in the SERVERS list:

Server setPropertyValueByName ${SERVER} MY_PROPERTY "some Value"

This command takes three arguments:

  • The name of the individual server on which you want to set a property. This is taken from the SERVERS list.
  • The name of the property that you want to set. In this case, the property is MY_PROPERTY, which you created at the start of this tutorial. (See Adding a new server property.)
  • The value that you want to set the property to. In this case, you are setting MY_PROPERTY to "some Value".

    Note

    In certain cases you might need to use double quotes to enclose arguments that contain special characters. For example:

    • If the property name ends with an asterisk.
    • If the value contains spaces.

Where to go from here

Now that you have examined the script, you need to add it to the Depot. See Adding the NSH script to the Depot.

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

Comments