6 Replies Latest reply on Jan 10, 2011 3:56 PM by Chris Alliey

    Help with NSH script

      I'm new to the NSH scripting, so I'm hoping someone can point me in the right direction. 


      I'm looking to write a script that can run on the application server, and pull information from the application server database.

      I'm specifically looking to have a script run on the application server that pulls the IP address from a server in the DB.


      I know when BMI runs after provisioning a system, the IP address (as well as MAC and other information) is pushed to the

      application server from the client.  That information gets stored in the DB, is there a way to pull that information or set it as a variable in a script?


      Is something like this possible? 


      Thanks in advance! 



        • 1. Help with NSH script
          Vinnie Lima

          Hey Chris,


          You probably should use NSH to call a blcli command on the app server.  AFAIK, the only way to extract data from the Bladelogic DB about a system is through blcli commands.


          blcli is kinda dopey in a way that you have to pass credentials, but it has a plethora of functions which extract exactly what you are looking for.


          Look at the lab system you have tehre, in the 7.6 Bladelogic system, under /opt/bmc/bcas/storage/extended_objects folder, there is an NSH script I used for SNMP compliance push/pull.  there is a sample BLCLI which gets an Attribute from a device class.


          There might be alternate ways in 8.0 (which I think is what you are using now?) but I do not know of them yet.


          I'll be there later this afternoon and can point you in the right direction if you still need help.


          Take care

          Vinnie Lima

          • 2. Help with NSH script
            Steve Bradshaw

            Hi Chris,

            I have used the following to pull the IP address from Bladelogic


            You will need to have some way of authenticating with the server, and if you have multiple roles you may have to specify a role.


            Hope this helps,









            if test $# -ne 1


                echo "usage: $0 <target hostname>"

                exit 1



            # IP address from the BL system.

            BL_AUTH_PROFILE_NAME=`blcred authprofile -list | grep Name | awk '{print $2}'`

            export BL_AUTH_PROFILE_NAME


            # Get IP Address from BL hostname

            IP_ADDR=`blcli Server printPropertyValue $1 IP_ADDRESS`


            echo $IP_ADDR

            • 3. Help with NSH script
              Bill Robinson

              if you are running the nsh/blcli script as a nshjob, you do not need to worry about credentials.


              what are you trying to do w/ that info?

              • 4. Help with NSH script

                Thanks for the help everyone.


                Bill -

                I'm looking to update a file (host file) on the application server with the IP address of the client that is being provisioned.  It appears I need this, as after the provisioning process is complete, I am still using a DHCP address and there is already an entry for the client in DNS.  The entry in the host file will be removed when the client gets it's final IP address (also scripted).


                What I don't know yet is if the information sent to the application server from BMI is updated in the database (I assume it is) and then how to access this information from a NSH script.


                I'm hoping that with the information provided above, I'll be able to automate that process - I will update when I'm done testing it. 


                Thanks for everyone's input!



                • 5. Re: Help with NSH script

                  Hi Chris,


                  Couldn't you just delete the "DHCP client" server object and then add a new server object?

                  I normally do this as part of my final post-provisioning step/package.


                  blcli_execute Server decommissionServer ${CURRENT_HOST} >${NULL}


                  blcli_execute Server addServer "${NEW_HOST}" > ${NULL}


                  I actually set the name for my deployments so I already know what the name and IP address are in my blcli script.

                  However you could probably use "blcli_execute Server getServerName"  to obtain the current servers name and then use that in your decommision command.


                  This method also has an additional advantage for me as my build network is separated from the rest of our networks. S o after the server build completes and the new server has its final name and IP address it still has no connectivity to the normal network.  The above creates the new server entry which shows "agent not responding" until the Network team switch the port from the build network to its production network and then everything works.

                  • 6. Help with NSH script


                    Thanks to everyone that assisted in resolving this problem!  I currently have a working script!!


                    The following script is what I ended up with: 




                    Running this script on the Application server, agains a given host allows me to put the IP/host name in the /etc/hosts file.  I will write another script that removes it from the host file when going into production.


                    Thanks Steve & Bill




                         cd //localhost

                         host_ipaddr=`blcli Server printPropertyValue $host_name IP_ADDRESS`

                         echo $host_ipaddr

                         echo "$host_ipaddr $host_name" >> /etc/hosts