--- /dev/null
+#!/bin/bash
+
+# This program runs pgfouine or pgbadger to process postresql logs
+# and outputs the reports into a pre-defined directory.
+# It will check to previous our from the time the program
+# is executed in order to get all transactions for the hour.
+
+
+########### Config Section ###########
+
+## The directory that the logs are stored in.
+LOGDIR="/var/log/evergreen"
+
+## The output directory.
+OUTDIR="/var/www/pg_reports"
+
+## The output filename.
+OUTFILE="$(date +%F)-pg"
+
+## The logfile for this script
+ANALYZER_LOG="/var/log/pg-log-analyzer.log"
+######################################
+
+
+## The date/time this script is run.
+RUN_DATE="$(date)"
+
+## The absolute path to the current day's logs file
+LOGPATH="$LOGDIR/$(date +%Y/%m/%d)"
+
+## The hour of time the program is run
+CURRENT_HOUR="$(date +%H)"
+
+## This subracts one hour from the current hour
+HOUR="$(( $(date +%k) - 1 ))"
+## Then we pad the $HOUR with a '0'
+HOUR="$(printf "%02d\n" $HOUR)"
+
+## The current day's log files
+LOGDAY="$(date +%Y/%m/%d)"
+
+
+## Since we check 1 hour behind
+## we make sure to set the day yesterday
+## when our current runtime is 12:00 AM
+if [ "$CURRENT_HOUR" = "00" ]
+then
+ HOUR="23"
+ LOGDAY="$(date -d '1 day ago' +%Y/%m/%d)"
+ OUTFILE="$(date -d '1 day ago' +%F)-pg"
+fi
+
+
+
+## This does the actual work.
+case $1 in
+pgfouine)
+ echo -n "$RUN_DATE " >> "$ANALYZER_LOG"
+ pgfouine -file $LOGDIR/$LOGDAY/pg.$HOUR.log -logtype stderr > $OUTDIR/$OUTFILE.$HOUR.log.html 2>> "$ANALYZER_LOG"
+;;
+pgbadger)
+ echo -n "$RUN_DATE " >> "$ANALYZER_LOG"
+ pgbadger --format syslog --outfile $OUTDIR/$OUTFILE.$HOUR.log.html $LOGDIR/$LOGDAY/pg.$HOUR.log 2>> "$ANALYZER_LOG"
+;;
+*)
+ echo
+ echo usage:-
+ echo "<$0 pgfouine> to use pgfouine -or-"
+ echo "<$0 pgbadger> to use pgbadger"
+ exit 1
+esac