# Grep command in a loop

**URL:** <https://community.unix.com/t/grep-command-in-a-loop/372324>\
**Category:** UNIX for Beginners Q & A\
**Created:** [May 16, 2018, 1:27pm UTC](https://community.unix.com/t/grep-command-in-a-loop/372324 "2018-05-16T13:27:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MSpeare](https://community.unix.com/letter_avatar/mspeare/32/6_449c533f586939b6e5f246632a46421f.png) [@MSpeare](https://community.unix.com/u/MSpeare)\
**Post date:** [May 16, 2018, 1:27pm UTC](https://community.unix.com/t/grep-command-in-a-loop/372324/1 "2018-05-16T13:27:35Z")

</div>

Hello -

I am running a script that is outputting to a log. Let call it output.log  
I would like to monitor that log until the line "Build Successful" is found.

I think I would need to use the grep command.  
How would I do that in a loop?

Thanks  
Marty

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/6_449c533f586939b6e5f246632a46421f.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [May 16, 2018, 1:37pm UTC](https://community.unix.com/t/grep-command-in-a-loop/372324/2 "2018-05-16T13:37:53Z")

</div>

It'd be much better to watch the return code of the script if you can. Usually it will return 0 for success, anything else for error.

You can do

```nohighlight
tail -f build.log | grep -l -q "Build Successful"

```

but if "Build Successful" never appears, it will wait forever.

The same problem faces any approach really. Without some way to tell when it's failed, it has no termination condition.
