running grep on a docker exec command's output
Clash 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.
shell-script docker
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.
add a comment |Â
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.
shell-script docker
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
add a comment |Â
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.
shell-script docker
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
shell-script docker
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
add a comment |Â
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
add a comment |Â
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...)
add a comment |Â
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 +'
add a comment |Â
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...)
add a comment |Â
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...)
add a comment |Â
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...)
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...)
answered Feb 8 '17 at 20:07
Hovav
112
112
add a comment |Â
add a comment |Â
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 +'
add a comment |Â
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 +'
add a comment |Â
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 +'
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 +'
edited Jul 15 at 9:40
answered Jul 15 at 9:07
Kusalananda
106k14209328
106k14209328
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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