title: How do I add `watch' command to a shell script?
body: <p>I have a script that greps and awks and counts for ip addresses with multiple http status codes.  It doesn't really matter what the script is though, because my goal is as follows:</p>
  
  <p>I want to invoke the `watch' command inside this script so that it will update the display every few seconds with new data received from the dynamic apache logs.</p>
  
  <p>i can call my script fine as follows:</p>
  
  <pre><code>$ watch --no-title ./bad_request.sh
  </code></pre>
  
  <p>But I would much rather have the `watch' command inside the script itself, to make calling the script from the command prompt much cleaner.</p>
  
  <p>Here is the script:</p>
  
  <pre><code>#!/bin/bash
  #identify repeated offenders through 401 and 403 status codes
    for ip in `awk '{print $1}' /var/log/apache2/* | sort -u`; do echo -n "$ip "; awk '{print $1 " " $9}' /var/log/apache2/* | egrep "( 401| 403)"| grep -c $ip; done | sort -k2 -r
  </code></pre>
  
  <p>Now, I have tried just inserting "watch -d --no-title" inside the script, right before the for loop, but it errors out angrily.  I think it's because it is only processing until it reaches the end of the first command.  I've tried putting backticks, and $() around the entire script, as well.  I've also tried making the bulk of the script a bash function, and calling watch on the function.  No dice.</p>
  
  <p>Any ideas?</p>
  
  <p>By the way, I'm also open to improvements on the script - I do realize it's a bit redundant/inefficient.  Of course, that should probably be reserved for a different Stack Overflow question.</p>
  
  <p>Thanks,</p>
  
  <p>Kevin</p>
  
  <p>EDIT:  And one more thing, I can just call <code>while true; do &lt;bulk of script&gt;; sleep 1; clear;</code> but I hate that.  It works, but the screen flickers, and it's just not the right way to do this.</p>
  
  <p>EDIT 2:  Another nasty hack that works, is to simply create two scripts.  The first one is:</p>
  
  <pre><code>watch --no-title ./bad_request
  </code></pre>
  
  <p>And then just call that script.  That works fine, but there has to be a better way.</p>
  
  <p>EDIT 3 (sorry...):  I took the -d flag off of `watch'.  It's not necessary for my script.</p>