#!/bin/bash # Define PDF detection regex pattern='GET /(.*.pdf)' # Grab latest lines in log file and check against regex tail -f access_log | grep --line-buffered .pdf | while read line; do echo $line if [[ $line =~ $pattern ]]; then # PDF filename is stored in BASH_REMATCH myfile=${BASH_REMATCH[1]} fi #Trigger for Universal Analytics endpoint, with event tracking wget -q -O /tmp/pixel.gif "http://www.google-analytics.com/collect?v=1&t=event&tid=UA-7634164-5&cid=555&dh=juliencoquet.com&ec=Downloads&ea=PDF&el=$myfile&ev=1&cm3=1" done