Created
May 18, 2015 15:26
-
-
Save marek-saji/d1f7f4a54d8d8ba96a09 to your computer and use it in GitHub Desktop.
eval "tail | grep" | cat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ~/foo.sh 2>/dev/null | |
I want this: | |
eval "tail -n100 -f /tmp/tmp.85E0vH3e5d | grep 'GET./foo'" | cat | |
(real use case is running `tail -f | grep` in this: https://github.com/marek-saji/task-runner.sh/blob/b876596dab86c30c57ee341ca4511e079a2ae4ff/src/task-runner.sh#L89-L91) | |
... but that doesn't work | |
Removing `| cat` makes it work: | |
eval "tail -n100 -f /tmp/tmp.85E0vH3e5d" | grep 'GET./foo' | |
GET /foo | |
so does dropping `-f` from `tail`: | |
eval "tail -n100 /tmp/tmp.85E0vH3e5d | grep 'GET./foo'" | grep 'GET./foo' | |
GET /foo | |
or `grep`: | |
eval "tail -n100 -f /tmp/tmp.85E0vH3e5d" | cat | |
GET /foo | |
GET /bar | |
or changing that grep to cat | |
eval "tail -n100 -f /tmp/tmp.85E0vH3e5d | cat" | cat | |
GET /foo | |
GET /bar |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LOG=$( mktemp ) | |
echo 'GET /foo' >> ${LOG} | |
echo 'GET /bar' >> ${LOG} | |
echo 'I want this:' | |
echo "eval \"tail -n100 -f ${LOG} | grep 'GET./foo'\" | cat" | |
echo '(real use case is running `tail -f | grep` in this: https://github.com/marek-saji/task-runner.sh/blob/b876596dab86c30c57ee341ca4511e079a2ae4ff/src/task-runner.sh#L89-L91)' | |
( eval "tail -n100 -f ${LOG} | grep 'GET./foo'" | cat ; ) & | |
PID=$! | |
sleep 1 | |
kill ${PID} 2>&1 > /dev/null | |
echo "... but that doesn't work" | |
echo | |
echo 'Removing `| cat` makes it work:' | |
echo "eval \"tail -n100 -f ${LOG}\" | grep 'GET./foo'" | |
( eval "tail -n100 -f ${LOG}" | grep 'GET./foo' ; ) & | |
PID=$! | |
sleep 1 | |
kill ${PID} 2>&1 > /dev/null | |
echo | |
echo 'so does dropping `-f` from `tail`:' | |
echo "eval \"tail -n100 ${LOG} | grep 'GET./foo'\" | grep 'GET./foo'" | |
( eval "tail -n100 ${LOG} | grep 'GET./foo'" | grep 'GET./foo' ; ) | |
echo | |
echo 'or `grep`:' | |
echo "eval \"tail -n100 -f ${LOG}\" | cat" | |
( eval "tail -n100 -f ${LOG}" | cat ; ) & | |
PID=$! | |
sleep 1 | |
kill ${PID} 2>&1 > /dev/null | |
echo | |
echo 'or changing that grep to cat' | |
echo "eval \"tail -n100 -f ${LOG} | cat\" | cat" | |
( eval "tail -n100 -f ${LOG} | cat" | cat ; ) & | |
PID=$! | |
sleep 1 | |
kill ${PID} 2>&1 > /dev/null | |
rm -rf ${LOG_DIR} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment