running grep on a docker exec command's output

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I'm re-phrasing the question because it was highly confusing and was badly phrased... )-:



I have a docker container and I'm reading logs from it like this:



docker exec -it my-container sh -c "export TERM=xterm && ls -t /logs/my-log.* | xargs zless -R"


now, I want to use 'grep' on the output and I am facing a problem because this one is working:



docker exec -it my-container sh -c "export TERM=xterm && ls -t /logs/my-log.* | xargs zless -R | grep sometext"


while this one is not working:



docker exec -it my-container sh -c "export TERM=xterm && ls -t /logs/my-log.* | xargs zless -R" | grep sometext


(note that the 1st working command includes the grep within the command I send and in the 2nd one I run grep on the output)



it is important to me because I am running the command in a script and I want to allow running grep on this script's output.










share|improve this question
















bumped to the homepage by Community♦ 2 days ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • What do you mean by multiple piped ones?
    – countermode
    Feb 7 '17 at 15:05










  • Something like that: scrpt my-container my-file | grep sometext | head -n 1
    – Hovav
    Feb 7 '17 at 18:16















up vote
0
down vote

favorite












I'm re-phrasing the question because it was highly confusing and was badly phrased... )-:



I have a docker container and I'm reading logs from it like this:



docker exec -it my-container sh -c "export TERM=xterm && ls -t /logs/my-log.* | xargs zless -R"


now, I want to use 'grep' on the output and I am facing a problem because this one is working:



docker exec -it my-container sh -c "export TERM=xterm && ls -t /logs/my-log.* | xargs zless -R | grep sometext"


while this one is not working:



docker exec -it my-container sh -c "export TERM=xterm && ls -t /logs/my-log.* | xargs zless -R" | grep sometext


(note that the 1st working command includes the grep within the command I send and in the 2nd one I run grep on the output)



it is important to me because I am running the command in a script and I want to allow running grep on this script's output.










share|improve this question
















bumped to the homepage by Community♦ 2 days ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • What do you mean by multiple piped ones?
    – countermode
    Feb 7 '17 at 15:05










  • Something like that: scrpt my-container my-file | grep sometext | head -n 1
    – Hovav
    Feb 7 '17 at 18:16













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm re-phrasing the question because it was highly confusing and was badly phrased... )-:



I have a docker container and I'm reading logs from it like this:



docker exec -it my-container sh -c "export TERM=xterm && ls -t /logs/my-log.* | xargs zless -R"


now, I want to use 'grep' on the output and I am facing a problem because this one is working:



docker exec -it my-container sh -c "export TERM=xterm && ls -t /logs/my-log.* | xargs zless -R | grep sometext"


while this one is not working:



docker exec -it my-container sh -c "export TERM=xterm && ls -t /logs/my-log.* | xargs zless -R" | grep sometext


(note that the 1st working command includes the grep within the command I send and in the 2nd one I run grep on the output)



it is important to me because I am running the command in a script and I want to allow running grep on this script's output.










share|improve this question















I'm re-phrasing the question because it was highly confusing and was badly phrased... )-:



I have a docker container and I'm reading logs from it like this:



docker exec -it my-container sh -c "export TERM=xterm && ls -t /logs/my-log.* | xargs zless -R"


now, I want to use 'grep' on the output and I am facing a problem because this one is working:



docker exec -it my-container sh -c "export TERM=xterm && ls -t /logs/my-log.* | xargs zless -R | grep sometext"


while this one is not working:



docker exec -it my-container sh -c "export TERM=xterm && ls -t /logs/my-log.* | xargs zless -R" | grep sometext


(note that the 1st working command includes the grep within the command I send and in the 2nd one I run grep on the output)



it is important to me because I am running the command in a script and I want to allow running grep on this script's output.







shell-script docker






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 8 '17 at 14:23

























asked Feb 7 '17 at 14:38









Hovav

112




112





bumped to the homepage by Community♦ 2 days ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community♦ 2 days ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.













  • What do you mean by multiple piped ones?
    – countermode
    Feb 7 '17 at 15:05










  • Something like that: scrpt my-container my-file | grep sometext | head -n 1
    – Hovav
    Feb 7 '17 at 18:16

















  • What do you mean by multiple piped ones?
    – countermode
    Feb 7 '17 at 15:05










  • Something like that: scrpt my-container my-file | grep sometext | head -n 1
    – Hovav
    Feb 7 '17 at 18:16
















What do you mean by multiple piped ones?
– countermode
Feb 7 '17 at 15:05




What do you mean by multiple piped ones?
– countermode
Feb 7 '17 at 15:05












Something like that: scrpt my-container my-file | grep sometext | head -n 1
– Hovav
Feb 7 '17 at 18:16





Something like that: scrpt my-container my-file | grep sometext | head -n 1
– Hovav
Feb 7 '17 at 18:16











2 Answers
2






active

oldest

votes

















up vote
0
down vote













the script is running 'exec -it', 't' stands for tty



zless is "thinking" it has a tty in front of it without the additional pipe...



removing the 't' solved the problem (although it is now acts like a zcat and not zless but since piping is working I can simply pipe it into less...)






share|improve this answer



























    up vote
    0
    down vote













    I don't really see the point of the pipeline. zless is an interactive program, and the output of ls is to be looked at, not parsed.



    Instead:



    ... sh -c 'zgrep PATTERN /logs/my-log.*'


    or, if there are too many files,



    ... sh -c 'for pathname in /logs/my-log.*; do zgrep PATTERN "$pathname"; done'


    or, more efficiently,



    ... sh -c 'find /logs/ -maxdepth 1 -type f -name "my-log.*" -exec zgrep PATTERN +'





    share|improve this answer






















      Your Answer







      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "106"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f343184%2frunning-grep-on-a-docker-exec-commands-output%23new-answer', 'question_page');

      );

      Post as a guest






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote













      the script is running 'exec -it', 't' stands for tty



      zless is "thinking" it has a tty in front of it without the additional pipe...



      removing the 't' solved the problem (although it is now acts like a zcat and not zless but since piping is working I can simply pipe it into less...)






      share|improve this answer
























        up vote
        0
        down vote













        the script is running 'exec -it', 't' stands for tty



        zless is "thinking" it has a tty in front of it without the additional pipe...



        removing the 't' solved the problem (although it is now acts like a zcat and not zless but since piping is working I can simply pipe it into less...)






        share|improve this answer






















          up vote
          0
          down vote










          up vote
          0
          down vote









          the script is running 'exec -it', 't' stands for tty



          zless is "thinking" it has a tty in front of it without the additional pipe...



          removing the 't' solved the problem (although it is now acts like a zcat and not zless but since piping is working I can simply pipe it into less...)






          share|improve this answer












          the script is running 'exec -it', 't' stands for tty



          zless is "thinking" it has a tty in front of it without the additional pipe...



          removing the 't' solved the problem (although it is now acts like a zcat and not zless but since piping is working I can simply pipe it into less...)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 8 '17 at 20:07









          Hovav

          112




          112






















              up vote
              0
              down vote













              I don't really see the point of the pipeline. zless is an interactive program, and the output of ls is to be looked at, not parsed.



              Instead:



              ... sh -c 'zgrep PATTERN /logs/my-log.*'


              or, if there are too many files,



              ... sh -c 'for pathname in /logs/my-log.*; do zgrep PATTERN "$pathname"; done'


              or, more efficiently,



              ... sh -c 'find /logs/ -maxdepth 1 -type f -name "my-log.*" -exec zgrep PATTERN +'





              share|improve this answer


























                up vote
                0
                down vote













                I don't really see the point of the pipeline. zless is an interactive program, and the output of ls is to be looked at, not parsed.



                Instead:



                ... sh -c 'zgrep PATTERN /logs/my-log.*'


                or, if there are too many files,



                ... sh -c 'for pathname in /logs/my-log.*; do zgrep PATTERN "$pathname"; done'


                or, more efficiently,



                ... sh -c 'find /logs/ -maxdepth 1 -type f -name "my-log.*" -exec zgrep PATTERN +'





                share|improve this answer
























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  I don't really see the point of the pipeline. zless is an interactive program, and the output of ls is to be looked at, not parsed.



                  Instead:



                  ... sh -c 'zgrep PATTERN /logs/my-log.*'


                  or, if there are too many files,



                  ... sh -c 'for pathname in /logs/my-log.*; do zgrep PATTERN "$pathname"; done'


                  or, more efficiently,



                  ... sh -c 'find /logs/ -maxdepth 1 -type f -name "my-log.*" -exec zgrep PATTERN +'





                  share|improve this answer














                  I don't really see the point of the pipeline. zless is an interactive program, and the output of ls is to be looked at, not parsed.



                  Instead:



                  ... sh -c 'zgrep PATTERN /logs/my-log.*'


                  or, if there are too many files,



                  ... sh -c 'for pathname in /logs/my-log.*; do zgrep PATTERN "$pathname"; done'


                  or, more efficiently,



                  ... sh -c 'find /logs/ -maxdepth 1 -type f -name "my-log.*" -exec zgrep PATTERN +'






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jul 15 at 9:40

























                  answered Jul 15 at 9:07









                  Kusalananda

                  106k14209328




                  106k14209328



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f343184%2frunning-grep-on-a-docker-exec-commands-output%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Christian Cage

                      How to properly install USB display driver for Fresco Logic FL2000DX on Ubuntu?