9 Replies Latest reply on Aug 6, 2015 7:36 AM by Yanick Girouard

    How to run a type 2 NSH Script with concurrency and target property support

    Yanick Girouard

      I have recently found a neat trick that opens the door to a lot possibilities and thought I would share it with the community. I needed a way to initiate reboots via a NSH script job and then wait for servers to come back up (with a sleep/agentinfo loop), but the shutdown was breaking the connection to the agent and returned an Exit Code 13 error (broken pipe). I needed this job to run concurrently against multiple targets and also needed to pass target property values to the script as parameters, so a Type 2 NSH Script job was no option.


      Then I remembered this: the only difference between a type 1 and type 2 NSH script job, is that the type 1 job is executed like this: nsh -D //??TARGET.NAME?? /path/to/script.nsh ..., and keeps an open pipe with the target (not sure how that part works, but it does), while type 2 only calls nsh with the script's path and its arguments, without the -D part. Both versions run against an app server the same way otherwise.


      Then I thought about the "cd //@; disconnect" trick, which basically returns the shell to the directory and host it was run from and disconnects from the target.


      So I tried this in my type 1 NSH Script; right at the beginning, I have added a  cd //@; disconnect to detach the NSH shell from the target and behave like a type 2 would, and simply used nexec $TARGET_NAME to call everything instead of using nexec -e and using full NSH paths instead of relative paths.


      The agent still needs to be alive and functional for the script to start (or it returns a cd //target error), but if you don't worry about that, you can do anything afterwards and it will never break the execution of the script because the connection with the agent was interrupted (i.e. initiate a restart or install a package that disrupts the network connection of the agent, etc...).


      Hope that will help a few!