5 Replies Latest reply on Apr 27, 2016 11:27 AM by Bill Robinson

    pass a console variable to a nsh shell script

    Charles Berman

      I want to a pass the target (or execute against) variable to an nsh shell script.

       

      This is the command that I am running in my script. I have tried HOST and TARGET but the log said they where not recognized. I also tried the syntax "{1}" but that doe not work.

       

      ssh -o BatchMode=yes -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@(??HOST??)

       

      Any help is greatly appreciated.

        • 1. Re: pass a console variable to a nsh shell script
          Bill Robinson

          ??xxx?? is not a shell construct.  {1} is also not correct - shell variables are referenced like ${1} or $1.

           

          if it's a type 1 nsh script you can use $NSH_RUNCMD_HOST.  that will be the target the script is executing against.

           

          if this is a type 2 script you will have the list of targets coming into the script as variables (%h) or a file (%f) which you can iterate through.

           

          if you are running a nsh script against a target, why are you trying to ssh from the appserver to the target ?

          • 2. Re: pass a console variable to a nsh shell script
            Charles Berman

            The project is to test root login abilities to a list of servers. The list of servers in this case where the variable.

             

            Can you direct me to the definitions or explaminations of a type 1 and type 2 nsh script? I am not familiar with them.

            • 3. Re: pass a console variable to a nsh shell script
              Bill Robinson

              Add NSH Script - Script Options - BMC Server Automation 8.7 - BMC Documentation

               

              • Execute the script separately against each host — The script executes repeatedly from the Application Server, each time running on a different server. This option uses the Network Shellrunscript program, which can run the same script on multiple machines. The script uses environment variables local to the Application Server.
              • Execute the script once, passing the host list as a parameter to the script — The script executes once against many servers. If you select this option, you must create a parameter that has a default value of %h or %f. When you execute the script, the %h macro is replaced by a space-delimited list of host names. The %f macro is replaced by a file containing a list of host names. The script uses environment variables local to the Application Server.
              • Copy and execute the script against each host separately — The script is repeatedly copied to different servers and then executed on each of those servers. The script uses environment variables local to the server where the script is executed. After execution, the script is deleted. Use this option for scripts that do not use Network Shell.
              • Execute the script using the PERL interpreter, passing the host list as a parameter to the script — The script executes using the Perl interpreter. If you select this option, you must create a parameter that has a default value of %h or %f. When you execute the script, the %h macro is replaced by a space-delimited list of host names. The %f macro is replaced by a file containing a list of host names.

               

              for type 1 and type 2 the nsh binary is run from the appserver, so if you invoke ssh from there it will be ssh on whatever appserver picked up the job.

               

              unless you have ssh keys setup i'm not sure how useful running the ssh command you have will be in determining if root ssh is enabled.  wouldn't it be better to check the /etc/ssh/sshd_config file for the value of PermitRootLogin and AllowUsers/AllowGroups ?

              • 4. Re: pass a console variable to a nsh shell script
                Charles Berman

                I am testing the change to PermitRootLogin parameter and validating that the sshd process was restarted and the change is in a effect.

                 

                Thank you.

                • 5. Re: pass a console variable to a nsh shell script
                  Bill Robinson

                  Ok – but you can’t pass passwords to ssh in clear text so the only way to see if you can login as root is if you have ssh keys setup for the root account on each target for the bladmin user on each appserver.