#!/bin/sh

# Squid Graph Parser (squid-graph.sh) v0.001 (initial release)

# Copyright (C) 2000 Ralf Heiringhoff <ralf@freeze.rhwd.de>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place, Suite 330, Boston, MA 02111-1307 USA

# The squid-graph.cgi can be found at
# http://web.xtreme.dhs.org/software/squid-graph.html

# Crontab entry
# /etc/cron.d/squid-graph
#######################
# Store the daily squid usage as ascii graph
#
#m      h       dom     mon     dow     user    command
#0       0       *       *       *       root    if [ -x /usr/local/sbin/squid-graph.sh ]; then /usr/local/sbin/squid-graph.sh; fi
#
# Changelog:
#
#       Just started.
#
# BUGS:
#
#   Report  bugs  to  ralf@freeze.rhwd.de. Include a complete,
#   self-contained example that  will  allow  the  bug  to  be
#   reproduced,  and say which version of clean.sh you are using.

# Where did you put your squid-graph.cgi
CMD='/usr/local/sbin/squid-graph.cgi'

# Where do you want to store your log-file?
LOGFILE='/var/log/squid-graph.log'

# Should we email the graph?
EMAIL='true'

# Who should get the graph via email 
EMAILADR='noc@yoursite.com'

DATE=`date +%d-%m-%y`
HOSTNAME=`uname -n`

# Check if there is already a log-file and save the old log-file.
if [ -e ${LOGFILE} ]; then
	mv ${LOGFILE} ${LOGFILE}.old
fi

# Check if the script is executeable and then run it.
if [ -x ${CMD} ]; then
	${CMD} >${LOGFILE}
else
	echo "${CMD} is not executable."
	exit 1
fi

# Check if we should now email the result.
if [ ${email}="true" ]; then
	if [ -r ${LOGFILE} ]; then
		cat ${LOGFILE} | mail -s "${HOSTNAME}: Daily Squid Graph ${DATE}" ${EMAILADR}
	else
		echo "${LOGFILE} is not readable."
		exit 1
	fi
fi

