Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Watch command line for string

(In bash) Is it possible to watch the output of a command line program and flag when a particular string occurs?

Basically my problem is that we have large build scripts that produce mountains of output to the console. I want to watch the console for say the word 'ERROR' and then alert me somehow.

I then know to go and watch the rest of the process/cancel it.

like image 730
Gary Bake Avatar asked Dec 26 '22 11:12

Gary Bake


1 Answers

You can grep for the string, but you would need to store the original output of make, which can be done using tee. Example using mplayer to play a sound file as soon as an error occurs:

make 2>&1 | tee make.log | grep -lq ERROR && mplayer alert.wav
like image 124
soulmerge Avatar answered Jan 05 '23 04:01

soulmerge