Skip to content

Instantly share code, notes, and snippets.

@philcryer
Created July 13, 2012 16:46
Show Gist options
  • Save philcryer/3105918 to your computer and use it in GitHub Desktop.
Save philcryer/3105918 to your computer and use it in GitHub Desktop.
Finds 50x errors in Varnishncsa logs and writes daily reports for later analysis
#!/bin/bash
# Desc: Finds 50x errors in Varnishncsa logs and writes daily reports for later analysis
# Tags: varnish, varnishlog, varnishncsa, varnishncsa logs, 500 errors, error reports, logs
TODAY_GREP=`date +%d/%b/%Y`
TODAY=`date +%Y%m%d`
REPORT_DIR="/tmp/varnish-500-report"
REPORT_FILE="${REPORT_DIR}/${TODAY}"
VARNISHNCSA_LOG="/var/log/varnish/varnishncsa.log"
if [ ! -f "${VARNISHNCSA_LOG}" ]; then
echo "FAILED: Varnishncsa log not found, is varnishncsa running?"; exit 1
fi
if [ ! -d "${REPORT_DIR}" ]; then
mkdir ${REPORT_DIR}
fi
cat ${VARNISHNCSA_LOG} ${VARNISHNCSA_LOG}.[0-9] | grep "\" 50[0-9] " | grep "\[${TODAY_GREP}\:" > ${REPORT_FILE}.tmp
COUNT=`cat ${REPORT_FILE}.tmp | wc -l`
mv ${REPORT_FILE}.tmp ${REPORT_FILE}_${COUNT}.txt
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment