4 Replies Latest reply on Jan 23, 2019 7:14 PM by Scott Rabinow

    Problems with AIX command in NSH

    Alexander Foldats

      Hello,

       

      I need to run the following command on AIX machines in an NSH script, but when i run it with a nexec i get an error that does not occur when I run it directly on the machine:

       

      nexec produccion "lslpp -q -c -h -Or $(lslpp -q -c -w /unix | cut -d: -f2) | tail -1 | cut -d: -f7-8"

      nsh: command not found: lslpp

      02/01/17:18;25;40

       

      and when I go into the machine in KSH mode:

       

      produccion# nexec -i -e ksh

      # lslpp -q -c -h -Or $(lslpp -q -c -w /unix | cut -d: -f2) | tail -1 | cut -d: -f7-8

      02/01/17:18;17;28

       

      It gives me the NSH error and return a different time. Any help regarding a way to launch this command in NSH?

       

      thanks for the help.

       

               

        • 1. Re: Problems with AIX command in NSH
          Davorin Stevanovic

          Hi Alexander,

           

          I see problem here in how you are invoking subshell, this is how I have done it:

           

          aixhost% nexec aixhost "lslpp -q -c -h -Or $(nexec -e lslpp -q -c -w /unix | cut -d: -f2) | tail -1 | cut -d: -f7-8"

          02/01/18:01;58;47

          aixhost%

           

          not sure if there is cleaner way of doing this but when opening new subshell of nsh you still need to call nexec to execute command remotely and not locally on appserver.

           

          Thanks
          D.

          1 of 1 people found this helpful
          • 2. Re: Problems with AIX command in NSH
            Alexander Foldats

            thanks! that did the trick. Did not realize that a new nexec had to be done in the internal command.

            • 3. Re: Problems with AIX command in NSH
              Bill Robinson

              i think what is happening there is the $() is being expanded by the shell before being sent to the target.  i don't have an aix box but this should be similar:

               

              these are the interfaces on my target:

              % nexec blapp893 "ip -o addr show"

              1: lo    inet 127.0.0.1/8 scope host lo\       valid_lft forever preferred_lft forever

              1: lo    inet6 ::1/128 scope host \       valid_lft forever preferred_lft forever

              2: ens192    inet 192.168.8.84/26 brd 192.168.8.127 scope global ens192\       valid_lft forever preferred_lft forever

              2: ens192    inet6 fe80::250:56ff:fe9e:beda/64 scope link \       valid_lft forever preferred_lft forever

              these are the interfaces on my client:

              % ip -o addr show

              1: lo    inet 127.0.0.1/8 scope host lo\       valid_lft forever preferred_lft forever

              2: eth0    inet 192.168.12.20/27 brd 192.168.12.31 scope global noprefixroute eth0\       valid_lft forever preferred_lft forever

               

              so my target does not have an eth0.

              % nexec blapp893 "ip -o addr show dev $(ip -o addr show | tail -1 | awk '{print $2}')"

              Device "eth0" does not exist.

              that's similar to the command you ran right ?  nexec this command w/ these args, one of which is derived on the fly.  since i'm getting eth0 for that subshell it's pretty clearly not making it to my target since that doesn't have an eth0.

               

              so i escape the $ (actually the one in my awk too):

              % nexec blapp893 "ip -o addr show dev \$(ip -o addr show | tail -1 | awk '{print \$2}')"

              2: ens192    inet 192.168.8.84/26 brd 192.168.8.127 scope global ens192\       valid_lft forever preferred_lft forever

              2: ens192    inet6 fe80::250:56ff:fe9e:beda/64 scope link \       valid_lft forever preferred_lft forever

              and it get the expected output.

              2 of 2 people found this helpful
              • 4. Re: Problems with AIX command in NSH
                Scott Rabinow

                I did test this against an AIX server, and Bill is correct that the only change to the original command was to escape the $ sign, with \$.

                 

                 

                The problem with the original command is that the $() is being expanded early and it's the second lslpp that is generating the error.  My first attempt generated 2 lines of output, like the original above, both the same error message and a date string followed by 3 semi-colon separated numbers.

                 

                I did not need to include an "nexec" prior to the second lslpp.  When I ran the command a second time (with the $ sign escaped), I got a different (more recent) date string followed by a different set of 3 semi-colon separated numbers, and most importantly - no errors!

                 

                Note: my BL infrastructure is running on Red Hat Linux servers where lslpp does not exist, so the results must be coming from the targeted AIX server in all cases.