title: Include User-Agent info in a nginx access log bash script
body: <p>I've got a working bash script that tells me nginx access logs as they come in, formatting the raw logs into colorful pieces of information.</p>
  
  <p>Unfortunately, I'm not quite sure how to take what I've already created, and add in showing the User-Agent of the request. I want to be able to look at a glance which User-Agent was used. Was it Googlebot? Was it Firefox 22 on Windows?</p>
  
  <p>Here's the bash script I have:</p>
  
  <pre><code>#!/bin/bash
  
  LOG_DEFAULT_PATH="/var/log/nginx/access.log"
  LOG_PATH="$1"
  
  if [ "$LOG_PATH" = "" ] &amp;&amp; test -f "$LOG_DEFAULT_PATH"; then
  
    echo -e "\033[35mAuto-detected Log File: \033[32m$LOG_DEFAULT_PATH\033[0m"
    LOG_PATH="$LOG_DEFAULT_PATH"
  
  fi
  
  if [ "$LOG_PATH" = "" ]; then
  
    echo -e "\033[32mUsage: $0 /path/to/nginx/access_log\033[0m"
  
  else
  
    (tail -n 500 -F $LOG_PATH | awk '{printf "%s%s %s %s%s%s %s %s %s%s%s %s%s\n", "\033[40;1;35m", $5, $6, "\033[0;32m", $1, "\033[37m", $10, substr($7, 2), "\033[31m", $8, "\033[36m", $2, "\033[0m"}')
  
  fi
  </code></pre>
  
  <p>The body of the script is in the line that begins with the tail command. I'm using awk to print the different pieces of the request into the terminal, and color each piece. It is here that I would assume the User-Agent information would also be shown.</p>
  
  <p>Here's the log format:</p>
  
  <pre><code>  log_format  vhost_combined  '$http_host $remote_addr - $remote_user [$time_local]  '
                                '"$request" $status $body_bytes_sent "$http_referer" '
                                '"$http_user_agent"';
  </code></pre>
  
  <p>Of course, any suggestions on better scripting would also be greatly appreciated!</p>