3 Replies Latest reply on Aug 14, 2012 4:34 PM by Bill Robinson

    Lookup target hostnames in bladelogic using a wildcard?


      HI, I am using a bladelogic nsh script to go to a host and retrieve a list hosts from a config file and then generate a job with multiple hosts as the targets. This part works fine, however some of the host names I am receiving may be in the short or long format and may not match what is in the bladelogic database.



      short host names are unique in bladelogic







      Lookup bladelogic targets using [shorthostname]* where star is represents a wildcard and return the matching target name that is in bladelogic.


      i.e. search bladelogic for host1* should return host1 or host1.fully.qualified.domain.com whichever is the valid target in bladelogic.





        • 1. Re: Lookup target hostnames in bladelogic using a wildcard?
          Bill Robinson

          by 'lookup' i'm assuming you mean run something like blcli Server findByName or something like that?  if so, then no, there is not a way to use a wildcard w/ that.


          there's probably 5 ways to do this, one would be to run 'blcli Server listAllServers' and grep for the shortname.

          • 2. Re: Lookup target hostnames in bladelogic using a wildcard?

            Thanks, Bill! I've got an initial solution working. I'll probably work on tweaking it to see if I can get faster results checking against a text file on host vs looking it up in bladelogic each time. If I find that to be true, I'll probably create a job to export the bladelogic server list to a file once a day and do lookups against that.


            I've posted my current prototype below.


            Thanks again,




            # read host list from file on linux server

            echo "Reading SERVER_NAME from ${SOURCE_LIST}..."

            # note: ignoring any records in the SOUCE_LIST with the "#" sign

            cat //${SOURCE_LIST}|grep -v "#"|while read SERVER_NAME


                echo "SERVER_NAME: $SERVER_NAME"

                # lookup SERVER_NAME in bladelogic

                # determine short SERVER_NAME by truncating at the first "." in SERVER_NAME

                SHORT_SERVER_NAME=`echo $SERVER_NAME|awk -F"." '{print$1}'`

                echo "SHORT_SERVER_NAME: $SHORT_SERVER_NAME"

                #blcli Server listAllServers

                #blcli Server listAllServers|grep $SHORT_SERVER_NAME

                MATCH_COUNT=`blcli Server listAllServers|grep $SHORT_SERVER_NAME|wc -l`

                    if [ $MATCH_COUNT -ne 1 ]


                    echo "ERROR: Unique match was not returned for $SHORT_SERVER_NAME when checking against bladelogic server list!"

                    echo "MATCH_COUNT: $MATCH_COUNT"

                    exit 1


                BL_SERVER_NAME=`blcli Server listAllServers|grep $SHORT_SERVER_NAME`

                echo "BL_SERVER_NAME: $BL_SERVER_NAME"

                date >> //$LOG_FILE

                echo "BL_SERVER_NAME: $BL_SERVER_NAME" >> //$LOG_FILE

                echo "MATCH_COUNT: $MATCH_COUNT"


                echo "--------------------------------------------------------------------------------"


            • 3. Re: Lookup target hostnames in bladelogic using a wildcard?
              Bill Robinson

              you might want to run the listAllServers command once and dump it to a file and do the lookups in there.

              1 of 1 people found this helpful