1

I'm working on a project, and it's being run by an autoscript. The script has the following line:

./executable ./dev | grep -i "GET.*index.*200" > ./dev/logs/log1

I have my code writing to stdout, but it never gets written to log1. If I change it though and remove the grep command, it writes just fine. Any help would be appreciated, as I seemingly don't understand grep as well as I should.

Pete B
  • 81
  • 1
  • 10
  • Nope, it isn't. Only stderr gets written there. – Pete B Dec 04 '14 at 15:19
  • 1
    possible duplicate of [How to 'grep' a continuous stream](http://stackoverflow.com/questions/7161821/how-to-grep-a-continuous-stream) – whoan Dec 04 '14 at 15:27
  • 2
    I'm assuming the output from your command actually matches that grep pattern? – Etan Reisner Dec 04 '14 at 15:46
  • 2
    it would be good to include some sample output from `executable` that you expect to match. Does the `executable` use colored output? That could throw off your grep. did you notice the option in grep for `--line-buffered` (or similar)? That might help too. Good luck. – shellter Dec 04 '14 at 16:39
  • have you tried using `>>` instead of `>`, or even `*>` – Quill Dec 05 '14 at 05:39

1 Answers1

1

You might try to redirect std output in your script "executable" using commands:

exec > ./dev/logs/log1
exec 2> ./dev/logs/errlog1

So, now not need to use ">" in the line

./executable ./dev | grep -i "GET.*index.*200"

Also I recommend you to use only absolute paths in scripts.

ps. [offtop] I can't write comments yet (not enough reputation).

fesia
  • 25
  • 5