6 Replies Latest reply on Mar 31, 2005 3:22 PM by Jim Carroll

    list of implicit nsh variables

      Share This:

      I'm trying to find a reference (eg, pdf) to a list of variables which nsh implicitly knows about. Of course, I'm assuming that nsh has this to begin with. :)


      Let me give an example of one thing I ran into which may or may not illustrate this.


      Let's say I'm currently on a host (point of origin, not sure of the proper terminology for BL) running under bash. And let's say I create the following script which happens to exist in the directory /home/jcarroll/foo/:




      cd //somehost

      cd $DIR


      Now, unless the directory /home/jcarroll/foo/ exists on the remote host, the last line of the script will fail. I understand why it works the way it does; I'm just hoping for A Better Way. I know I can reset to my originating host with just a simple 'cd', after which I can do the "cd $DIR". But I'm hoping that nsh has another way of doing this, e.g.,




      cd //somehost

      cd $NSHHOME/$DIR


      Or something like that.


      So, does nsh have such a built-in variable? Or is there an even better approach that I'm completely overlooking?

        • 1. Re: list of implicit nsh variables

          There are two kinds of paths in nsh: host-relative (/etc/passwd) and host-specific (//servername/etc/passwd).

          The problem you are seeing is that if you are in the context of the computer that is running nsh (the localhost), then pwd (and $PWD) is a host-relative path.


          It is a slightly unfortunate reality that the following does not always work in nsh:



          cd //someserver/tmp


          cd $DIR


          There is a host called //@ which is the current localhost. So if you know you are on the localhost, instead, you can try:



          cd //someserver/tmp


          cd //@/$DIR

          • 2. Re: list of implicit nsh variables

            Excellent, thanks.


            So while we're on the subject, are there any other nsh-specific features (analogous to '@') which would be worth knowing about?

            • 3. Re: list of implicit nsh variables

              There is not a lot of nsh specific documentation but you can try:

              man nsh

              man zsh

              man zshall


              Most people have enough to work with unix shell technologies -- if, while, for, test, ``, $VARIABLE, etc...


              Some fun nsh commands:

              n* (ntop, nover, ndf, nps, nnet, nmem...) - many standard commands that can be run in network enabled mode.


              logman - looking at agent log files using nsh.


              disconnect - disconnect from a server when you have used //server. Important if you are going to shutdown the agent.

              • 4. Re: list of implicit nsh variables

                I like '$NSH_RUNCMD_HOST', it is the current host on which the script is being executed.


                I use it a lot in NSH scripts that I make NSH script jobs.


                It allows me to use the 'run the script once using runscript' and not have to worry about iterating through the list of hosts that are passed to the script.


                So for a script like this (called say, 'echo_servername.nsh'):


                echo $SERVER_NAME

                If you run it from the command line like so:

                runscript -h host1 host2 -e echo_servername.nsh

                You'll get output like:

                ==> host1 <==
                ==> host2 <==

                Then you can create an nsh script job based on the script and use the 'run once using runscript' option. The group/list of servers you target with the job end up populating the -h option.

                • 5. Re: list of implicit nsh variables

                  Thanks for the tip on the man page for nsh. That was actually (somewhat) useful. zsh doesn't really help me, as I believe nsh is a superset of zsh, but with the BL networking and security integrated. I'm more familiar with sh and bash, but that's a personal choice. Many many years of being familiar with if, while, for, test, ``, $VARIABLE, and the like, but that wasn't what I was asking for.


                  The n* commands are all referenced in the BladeLogicNSHCommands.pdf file. Alas, there's no joy when it comes to finding references to the built-ins which set nsh apart. I'd hoped to find them there, but.... That's actually where I first looked prior to my post.


                  In other words, what BL-specific functionality/variables/references/operators/etc set nsh apart from zsh? Is there a central reference somewhere, or is it passed through tribal knowledge?

                  • 6. Re: list of implicit nsh variables

                    Good deal, Aaron.


                    Okay, so now we have '@' and '$NSH_RUNCMD_HOST". That's two. Is that the list of nsh's uniqueness in its entirety?


                    I suspect not, but until I find the holy grail of an authoritative reference, the search will continue.