4 Replies Latest reply on Jan 9, 2014 3:14 AM by Dipak Gaigole

    nexec and extended globbing

      Is is possible to use extended globbing with nexec?

       

      ### what I'm testing with on the local bl appserver

      [bladmin@myserver test]$ pwd

      /data/test

      [bladmin@myserver test]$ ls

      a123b.txt  a12.txt  a1.txt  b123c.txt  b12.txt  b1.txt

       

      ### local testing

      [bladmin@myserver test]$ shopt -s extglob

      [bladmin@myserver test]$ ls *(a*txt|b123*txt)

      a123b.txt  a12.txt  a1.txt  b123c.txt

      [bladmin@myserver test]$ myvar="*(a*txt|b123*txt)"

      [bladmin@myserver test]$ ls ${myvar}

      a123b.txt  a12.txt  a1.txt  b123c.txt

       

      ### remote testing (but using the same server and directory)

      [bladmin@myserver test]$ nexec myserver "shopt -s extglob;ls /data/test/${myvar}"

      /bin/bash: -c: line 0: syntax error near unexpected token `('

      /bin/bash: -c: line 0: `shopt -s extglob;ls *(a*txt|b123*txt)'

       

      nexec myserver "shopt -s extglob;ls /data/test/*(a*txt|b123*txt)"

      also produces the same result

       

      I'm guessing that the wrong shell is interpretting $myvar... any suggestions?

        • 1. Re: nexec and extended globbing
          Bill Robinson

          nexec server "shopt -s extglob;ls \"${myvar}\""

           

          ?

          • 2. Re: nexec and extended globbing
            Bill Robinson

            actually, that won't work...

             

            why not just do this in nsh directly ?

             

            ls //server/dir *(a*txt|b123*txt)

             

            ?

            • 3. Re: nexec and extended globbing

              well, a little progress...

               

              ### Bill's example with a space

              adm0012% ls //myserver/test *(a*txt|b123*txt)

              a1.txt     a12.txt    a123b.txt  b123c.txt

               

              //myserver/test:

              a1.txt     a12.txt    a123b.txt  b1.txt     b12.txt    b123c.txt  tt

               

              ### removed the space: (this is the type of returned data I'm expecting)

              adm0012% ls //myserver/test/*(a*txt|b123*txt)

              //myserver/test/a1.txt     //myserver/test/a123b.txt

              //myserver/test/a12.txt    //myserver/test/b123c.txt

               

              ### putting the glob into a variable... doesn't work

              adm0012%  myvar="a*txt|b123*txt"

              adm0012% ls //myserver/test/*($myvar)

              nsh: number expected

              adm0012%

               

              ### escaping results in a file not found

              adm0012% ls //myserver/test/\*\(${myvar}\)

              ls: //myserver/test/*(a*txt|b123*txt): No such file or directory

               

              your example brings up an intesting point though... doing an

              ls //server//anypath *(a*txt|b123*txt)

              (note the extra space) will show that path and the globbed files... where is 'ls' finding the files?  is there a locate database or something 'ls' looks in first?

               

              this is going to be used in bl-deploy script where "myvar" is a ??variable??

              • 4. Re: nexec and extended globbing
                Dipak Gaigole

                rhel-appserver01# nexec localhost  "shopt -s extglob; ls /tmp/test/*(a*txt|b123*txt)"

                /bin/bash: -c: line 0: syntax error near unexpected token `('

                /bin/bash: -c: line 0: `shopt -s extglob; ls /tmp/test/*(a*txt|b123*txt)'

                rhel-appserver01#

                 

                The above error is thrown by the shell which is executing the "shopt -s ...; ls ...." command. And this is not specific to nexec and can be reproduced natively as well:

                 

                Using native OS shell:

                [root@rhel-appserver01 tmp]# sh -c "shopt -s extglob; ls /tmp/test/*(a*txt|b123*txt)"

                sh: -c: line 0: syntax error near unexpected token `('

                sh: -c: line 0: `shopt -s extglob; ls /tmp/test/*(a*txt|b123*txt)'

                [root@rhel-appserver01 tmp]#

                 

                To fix this behavior, we need to use:

                [root@rhel-appserver01 tmp]# sh -O extglob -c "ls /tmp/test/*($myvar)"

                /tmp/test/a123b.txt  /tmp/test/a12.txt  /tmp/test/a1.txt  /tmp/test/b123c.txt

                [root@rhel-appserver01 tmp]#

                 

                 

                Using BladeLogic:

                Now the same should work through nexec:

                rhel-appserver01# nexec localhost sh -O extglob -c "ls /tmp/test/*(a*txt|b123*txt)"

                /tmp/test/a123b.txt  /tmp/test/a12.txt  /tmp/test/a1.txt  /tmp/test/b123c.txt

                rhel-appserver01#

                 

                Check with variable:

                rhel-appserver01#

                rhel-appserver01# myvar="*(a*txt|b123*txt)"

                rhel-appserver01# nexec localhost sh -O extglob -c "ls /tmp/test/*($myvar)"

                /tmp/test/a123b.txt  /tmp/test/a12.txt  /tmp/test/a1.txt  /tmp/test/b123c.txt

                rhel-appserver01#

                 

                Hope this helps...