1 2 Previous Next 15 Replies Latest reply on Jul 14, 2011 7:42 AM by Bill Robinson

    Works in NSH, but not in NSHScript Job

      I have a script that compares servers btw two bladelogic environments.  I starts by connecting to both appservers using 2 existing SRP autorization profiles (one for each server).  The script works fine when executed from NSH shell manually.

      I intend to use it as a scheduled job though but when I add it to Depot and execute it as NSH script job it fails.

      What's happening is - I end up with the same set of servers in both variables below SERVER_LIST_SOURCE and SERVER_LIST_TARGET

      (when if I run in NSH shell manually these variables contain a list of servers from each respective environment )

      Any ideas would be greatly appreciated.

       

      SERVER_LIST_SOURCE=""
      SERVER_LIST_TARGET=""

      blconnect() {
        blcred cred -acquire -profile "$1" -username XXXXXXX -password XXXXXXX
        blcli_setoption authType SRP
        blcli_setoption roleName nonBladminrole
        blcli_setoption serviceProfileName "$1"
        blcli_connect
      }
      get_servers() {
      blconnect "$1"
      blcli_execute Server listAllServers
      blcli_storeenv $2
      }

      get_servers "Prod 1 [SRP]" SERVER_LIST_SOURCE
      blcli_disconnect
      get_servers "Prod 2 [SRP]" SERVER_LIST_TARGET

        • 1. Works in NSH, but not in NSHScript Job

          just want to clarify what the problem is the way I see it

          I seem to have a problem when I try to use "blcred cred -acquire" for the second time in the same script (acquiring a different profile, connecting to another server)

          so it goes like this (simplified)

          blcred cred -acquire -profile "$1" -username XXXXXXX -password XXXXXXX

          blcli_setoption authType SRP

          blcli_setoption roleName nonBladminrole

          blcli_setoption serviceProfileName "$1"

          blcli_connect

          blcli_execute Server listAllServers

          blcli_storeenv SERVER_LIST_SOURCE

          blcli_disconnect

          blcred cred -acquire -profile "$2" -username XXXXXXX -password XXXXXXX <--does not work (I can swap profiles, it always fails on second one regardless)  Only a problem when executing as NSHScript job - works in NSH from command line.

          • 2. Works in NSH, but not in NSHScript Job
            Bill Robinson

            in the job you need to take out the blcred, and the setoptions.  those are not needed when run inside a nsh job.

            • 3. Works in NSH, but not in NSHScript Job
              Milton Stamper

              It looks like your environment is a bit different (we use card readers), but the principle should be the same.

               

              I was having the same issue and Bill told me that the Utility assumeRole command is for use in scripts.

               

              See https://communities.bmc.com/communities/message/191430#191430. Hope it helps.

              • 4. Works in NSH, but not in NSHScript Job
                Bill Robinson

                This use case is a little different because he need to connect to a different bladelogic install.

                • 5. Works in NSH, but not in NSHScript Job

                  the bizarre part is that this used to work in NSH window at least but not anymore. Every time I try if fails when connecting to the second server with: blconnect:7: message too long: blcred Exception in thread "main" com.bladelogic.session.client.SessionLoginException: No cached Session Credential for named service profile - please login. but first connection always succedes (and it does not matter which one goes first, I can reverse them)

                  • 6. Works in NSH, but not in NSHScript Job
                    Bill Robinson

                    instead of doing the disconnect, do a blcli_destroy

                    • 7. Works in NSH, but not in NSHScript Job

                      Tried that - no luck, same error.

                      • 8. Works in NSH, but not in NSHScript Job
                        Bill Robinson

                        From a nsh script (not job), this works for me:

                         

                        blcred cred -acquire -profile profile1 -username user1 -password password1

                        blcli_setoption serviceProfileName profile1

                        blcli_setoption roleName BLAdmins

                        blcli_connect

                        blcli_execute Server listAllServers

                        blcli_destroy

                        blcred cred -acquire -profile profile2 -username user2 -password password2

                        blcli_setoption serviceProfileName profile2

                        blcli_setoption roleName BLAdmins

                        blcli_connect

                        blcli_execute Server listAllServers

                         

                         

                         

                         

                         

                         

                         

                         

                         

                         

                         

                         

                         

                         

                         

                         

                         

                         

                         

                         

                         

                         

                         

                         

                         

                         

                         

                         

                         

                         

                         

                         

                         

                        • 9. Works in NSH, but not in NSHScript Job

                          Bill,

                          I was doing exactly the same with only one difference:

                           

                          blcli_execute Server listAllServers

                          blcli_storeenv <variable>

                           

                          I commrented out "blcli_storeenv <variable>" as a test and the script stopped crashing!

                          Question is why?

                          I use the same function twice: first for the source environment and it stores it no problem into var1

                          second time around it crashes if i have blcli_storeenv line present and I don't even see the output of listAllServers prior to it even though it comes before blcli_storeenv  line.

                          • 10. Works in NSH, but not in NSHScript Job
                            Bill Robinson

                            i ran it w/ the storeenv and it's ok in my setup too.

                             

                            blcred cred -acquire -profile profile1 -username user1 -password password1

                             

                            blcli_setoption serviceProfileName profile1

                            blcli_setoption roleName BLAdmins

                            blcli_connect

                            blcli_execute Server listAllServers

                            blcli_storeenv serverList

                            blcli_destroy

                            blcred cred -acquire -profile profile2 -username user2 -password password2

                            blcli_setoption serviceProfileName profile2

                            blcli_setoption roleName BLAdmins

                            blcli_connect

                            blcli_execute Server listAllServers

                            blcli_storeenv serverList

                            can you paste the latest version of your script?

                            • 11. Works in NSH, but not in NSHScript Job

                              its being called here: get_servers "$BL_SOURCE" SERVER_LIST_SOURCE blcli_destroy get_servers "$BL_TARGET" SERVER_LIST_TARGET and get_servers() does all the work full script: ------------------------------------ #!/bin/nsh EXISTING_SERVERS=0 ADDED_SERVERS=0 DELETED_SERVERS=0 TOTAL_SERVERS_SOURCE=0 TOTAL_SERVERS_TARGET=0 CONST_BL_SOURCE="Old Production [SRP]" CONST_BL_TARGET="Production [SRP]" CONST_MODE="add" BL_SOURCE=$CONST_BL_SOURCE BL_TARGET=$CONST_BL_TARGET MODE=$CONST_MODE SERVER_LIST_SOURCE="" SERVER_LIST_TARGET="" ARGUMENTS=0 ################################## # Connect to Bladelogic system # using specified Auth Profile ################################## blconnect() { echo Connecting to $1\\n blcred cred -destroy blcred cred -acquire -profile "$1" -username XXXXXXXXXXXXXXX -password XXXXXXXXXXX blcred cred -list blcli_setoption authType SRP blcli_setoption roleName BLadmins blcli_setoption serviceProfileName "$1" blcli_connect   } ################################## # Get a list of servers in bladelogic ################################## get_servers() { echo Getting a list of servers from $1 ... blconnect "$1" blcli_execute Server listAllServers blcli_storeenv "$2" } ################################## # Output usage information ################################## print_usage() { echo "Usage: \\n" echo "blsync.nsh -s -t -m \\n" } debug_print_vars(){ echo '=====================' echo 'BLSYNC.NSH Arguments:' echo '=====================' echo ARGUMENTS=$ARGUMENTS echo SOURCE=$BL_SOURCE echo TARGET=$BL_TARGET echo MODE=$MODE } ################################## # Add servers ################################### add_servers() { for SERVER_SOURCE in $SERVER_LIST_SOURCE do ERROR=false SERVER_EXISTS=NA SERVER_ID=-1 ### # is server in RBAC? If it isn't, add it. ### blcli_execute Server serverExists $SERVER_SOURCE blcli_storeenv SERVER_EXISTS if [ "$SERVER_EXISTS" = "false" ] then echo Adding server $SERVER_SOURCE SERVER_ID="Operation failed" blcli_execute Server addServer $SERVER_SOURCE blcli_storeenv SERVER_ID RESULT=`echo $SERVER_ID | grep failed` if [ -n "$RESULT" ] then echo Failure to add server: $RESULT ERROR=true else ADDED_SERVERS=$((ADDED_SERVERS+1)) echo Server $SERVER_SOURCE was added successfully. SERVER_ACL="Operation failed" echo "Modifying Permissions: Adding BLAdmins Server.* on Server $SERVER_SOURCE" blcli_execute Server addPermission $SERVER_SOURCE BLAdmins 'Server.*' system echo "Modifying Permissions: Adding WebOps_Admins Server.* on Server $SERVER_SOURCE" blcli_execute Server addPermission $SERVER_SOURCE WebOps_Admins 'Server.*' system blcli_storeenv SERVER_ACL RESULT=`echo $SERVER_ACL | grep failed` if [ -n "$RESULT" ] then echo Failure to modify ACLs: $RESULT ERROR=true else echo Permissions modified successfully. fi fi else blcli_execute Server getServerIdByName $SERVER_SOURCE blcli_storeenv SERVER_ID echo Server $SERVER_SOURCE already exists in RBAC. SERVER_ID=$SERVER_ID EXISTING_SERVERS=$((EXISTING_SERVERS+1)) fi done } ################################## # Delete servers ################################### delete_servers() { echo Deleting any extra servers not found in source... for SERVER_TARGET in $SERVER_LIST_TARGET do ERROR=false SERVER_ID=-1 RESULT="" RESULT=`echo $SERVER_LIST_SOURCE  | grep $SERVER_TARGET` if [ -n "$RESULT" ] then echo Keeping server $SERVER_TARGET else echo Decommissioning server $SERVER_TARGET blcli_execute Server decommissionServer $SERVER_TARGET false DELETED_SERVERS=$((DELETED_SERVERS+1)) fi done } ################################## # Check arguments # if none - fall back to defaults ################################## ARGUMENTS=$# typeset -u MODE if [ $# -ne 0 ] then while getopts s:t:m: o do     case "$o" in           s) BL_SOURCE=$OPTARG;;           t) BL_TARGET=$OPTARG;;           m) MODE=$OPTARG;;     esac done fi typeset -u SERVER_LIST_SOURCE typeset -u SERVER_LIST_TARGET debug_print_vars get_servers "$BL_SOURCE" SERVER_LIST_SOURCE blcli_destroy get_servers "$BL_TARGET" SERVER_LIST_TARGET exit # TOTAL_SERVERS_SOURCE=${#SERVER_LIST_SOURCE[@]} # TOTAL_SERVERS_TARGET=${#SERVER_LIST_TARGET[@]} case $MODE in DELETE) delete_servers ;; ADD) add_servers ;; MIRROR) add_servers delete_servers ;; esac echo \\n\\n echo SKIPPED EXISTING_SERVERS = $EXISTING_SERVERS \\n echo ADDED_SERVERS = $ADDED_SERVERS \\n echo DELETED_SERVERS = $DELETED_SERVERS \\n # echo TOTAL SOURCE SERVERS = $TOTAL_SERVERS_SOURCE # echo TOTAL TARGET SERVERS = $TOTAL_SERVERS_TARGET blcli_disconnect exit 0

                              • 12. Works in NSH, but not in NSHScript Job

                                maybe it has something to do with memory?

                                • 13. Works in NSH, but not in NSHScript Job
                                  Bill Robinson

                                  can you repaste that, the formatting got all messed up.

                                  • 14. Re: Works in NSH, but not in NSHScript Job

                                    I can only paste in HTML mode and it looks ok initially, once I save it it gets all messed up.  Any ideas? Maybe I can email it to you directly?

                                    1 2 Previous Next