Thursday, April 1, 2010

Echo and Process from cmdline

Here is a quick one for the sys admin tasks. I want to execute a command, and based on the output, not the exit code, execute something else. At the same time, I want to see the output of the original program displayed on the screen. The following does not work because grep swallows the input.

$ cmd | grep 'pattern to find' && doSomething

My current solution is not optimal, me thinks, but at least it lets me see what the original output is. Here is what I have:

$ cmd | tee /dev/stderr | grep -q 'pattern to find' && doSomething

Got any other way to do this?

P.D. I hate blogger's formatting...

No comments: