2 Replies Latest reply on Sep 22, 2014 10:18 AM by David Muench

    NSH Type 2 output format tricks?

    David Muench

      I've discovered from elsewhere on communities that if you prepend an output line in an NSH type 2 script with (target) it will file that line's output under the target's section instead of in the main output of the script.


      Are there other tricks like this? Can I return an error status for a given target without erroring out the entire script? Or affect the message type that is shown in the GUI?

        • 1. Re: NSH Type 2 output format tricks?
          John Landells

          We use a "prefix()" function to get the exit code against the correct server:


            { { "$@" | sed "s/^/$prefix /"; return ${pipestatus[1]}; } 3>&1 1>&2 2>&3 | sed "s/^/$prefix /"; return ${pipestatus[1]}; } 3>&1 1>&2 2>&3


          By way of an example, here it is in context:


          prefix() {
              { { "$@" | sed "s/^/$prefix /"; return ${pipestatus[1]}; } 3>&1 1>&2 2>&3 | sed "s/^/$prefix /"; return ${pipestatus[1]}; } 3>&1 1>&2 2>&3
          for SERVER in $*
              echo "($SERVER)" "Setting property: $PROPERTY = $VALUE"
              prefix "($SERVER)" blcli_execute Server setPropertyValueByName ${SERVER} "${PROPERTY}" "${VALUE}"
              echo "($SERVER)" "Exit code $rc"
              if [ $rc -gt $RC ]; then
          exit $RC

          To understand how this works, have a look at the key line:

          {{"$@"|sed"s/^/$prefix /"; return${pipestatus[1]}; }3>&11>&22>&3|sed"s/^/$prefix /"; return${pipestatus[1]}; }3>&11>&22>&3
          This command runs in several parts:


          1. We execute the command and pipe it's stdout through sed to prefix the output with the server name in order to get the logging in the correct place, returning the output from the original command (courtesy of $pipestatus[1]) so that the appropriate exit status is maintained.
          2. Since sed only process the stdout from the pipe, we then swap stdout and stderr (this is done using 3>&1 1>&2 2>&3) in order to effectively pipe stderr into the second sed statement - again making sure we're returning the appropriate status.
          3. Finally, we swap stdout and stderr back again to be sure the message shows up correctly in the BladeLogic GUI.


          Hope that helps!


          God bless,



          P.S. The syntax highlighting is playing up in preview mode - hope it's readable when I post it.....

          • 2. Re: NSH Type 2 output format tricks?
            David Muench

            That's pretty cool John, I will have to play with that..


            So to answer part of my own question, and this is really obvious once you think about it, output will show up as an Error type if the output line is echoed to stderr. So that's something, I haven't found a way to have a specific target show up as errored in the GUI though.