2 Replies Latest reply on Feb 21, 2013 11:53 AM by Dale Reagan

    How to reference 'external NSH functions' in an NSH script job?

    Dale Reagan

      I have written a number of NSH scripts which I run from the 'command line'.   My scripts typically reference a set of 'common functions' - the functions do simple things like send an email using BLCI commands.  I incorporate them by using something like:

       

          source "${BIN_DIR}/myfunctions.nsh"

       

      I am now moving some of these tools into the BL Depot and will then create 'jobs' to run them.  I'd prefer to limit any re-writes if I can (i.e. duplicating my shared functions in all, new 'NSH Job scripts' is less than preferred, but I will do it if there is no alternative...)

       

      • Is there a way to do this withing NSH Script jobs? (guessing some sort of BLCLI command that locates a 'shared-function' resource? or, perhaps something simpler, i.e. reference a fixed-file-name on the app server?)
      • Where would I store my 'shared functions'?
      • How would I reference them?

       

      Thanks!

       

       

      Dale

        • 1. Re: How to reference 'external NSH functions' in an NSH script job?

          two alternatives:

           

           

          1. Keep only the main scripts in BL depot. All your functions/libraries on a fixed path on appserver owned by bladmin/appserver user.

           

          In this case, the main scripts can source the functions with full abosulte path , please note that relative path will not work as the script is copied to a temporray area while execution as a NSH job.

          If you have multiple appserver, you may have to put this in same path on all appservers.

           

          2. Second option is to add the function scripts/libraries in BL depot.

          In this case , as said earlier, the script is copied to a temp location, you need to get File server location for these function scripts, create a directory in your main script in current working directory of the running script, and then copy the function script there and then source it

          e.g

          blcli_execute DepotFile getDBKeyByGroupAndName  $DEPOT_FOLDER_NAME  $DEPOT_NSH_SCRIPT_NAME

          blcli_execute DepotFile getLocation

          blcli_storeenv DEPOTFILELOCATION

          mkidir temp_librairies

          cp $DEPOTFILELOCATION temp_librairies

          source ./temp_librairies/$DEPOTFILELOCATION

           

           

          Hope this helps.

           

          Rohit

          1 of 1 people found this helpful
          • 2. Re: How to reference 'external NSH functions' in an NSH script job?
            Dale Reagan

            Thanks Rohit - both options look promising (have not tried yet.)

             

            - I coded 'around' this for now and used simple, one-line 'functions' as replacments - so things still work...

             

             

            Dale