#!/bin/sh -ue # # Copyright (C) 2008 Red Hat, Inc. # Author: Andreas Thienemann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU Library General Public License as published by # the Free Software Foundation; version 2 only # # 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 Library General Public License for more details. # # You should have received a copy of the GNU Library 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. # Copyright 2004, 2005 Red Hat, Inc. # # AUTHOR: Andreas Thienemann # # Location of the temporary flowmon-web files wwwtmp='/var/www/html/flowmon-web/tmp' # Location of the flowmon config.py file # Needed for the database credentials confpath='/etc/flowmon/config.py' # Days to keep the flowdata before expiring keeptime=90 #################################################### # Delete temporary files from the webinterface #/bin/find ${wwwtmp} -mmin +10 | /usr/bin/xargs /bin/rm -f #################################################### # Get the database credentials from the config file DATABASE=$(awk '/^DATABASE/ { print substr(substr($3, 2), 0, (length($3) - 2)) }' $confpath) DB_HOST=$(awk '/^DB_HOST/ { print substr(substr($3, 2), 0, (length($3) - 2)) }' $confpath) DB_NAME=$(awk '/^DB_NAME/ { print substr(substr($3, 2), 0, (length($3) - 2)) }' $confpath) DB_USER=$(awk '/^DB_USER/ { print substr(substr($3, 2), 0, (length($3) - 2)) }' $confpath) DB_PASS=$(awk '/^DB_PASS/ { print substr(substr($3, 2), 0, (length($3) - 2)) }' $confpath) # Build the SQL Delete string TIMESPEC=$(date -u -d "${keeptime} days ago" "+%s") SQL="START TRANSACTION; \ DELETE FROM Flows \ WHERE TimeStart < ${TIMESPEC}; \ COMMIT;" # Expire old data if [ "$DATABASE" == "mysql" ]; then echo $SQL | mysql -h $DB_HOST -u$DB_USER -p$DB_PASS $DB_NAME else echo "TODO: pgsql cmdline support" fi