root/trunk/cleanup.sh

Revision 1, 2.1 kB (checked in by ixs, 16 years ago)

initial checkin of RH revision

  • Property svn:executable set to *
Line 
1 #!/bin/sh -ue
2 #
3 # Copyright (C) 2008 Red Hat, Inc.
4 # Author: Andreas Thienemann <athienem@redhat.com>
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU Library General Public License as published by
8 # the Free Software Foundation; version 2 only
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU Library General Public License for more details.
14 #
15 # You should have received a copy of the GNU Library General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # Copyright 2004, 2005 Red Hat, Inc.
19 #
20 # AUTHOR: Andreas Thienemann <athienem@redhat.com>
21 #
22
23 # Location of the temporary flowmon-web files
24 wwwtmp='/var/www/html/flowmon-web/tmp'
25
26 # Location of the flowmon config.py file
27 # Needed for the database credentials
28 confpath='/etc/flowmon/config.py'
29
30 # Days to keep the flowdata before expiring
31 keeptime=90
32
33 ####################################################
34
35 # Delete temporary files from the webinterface
36 #/bin/find ${wwwtmp} -mmin +10 | /usr/bin/xargs /bin/rm -f
37
38 ####################################################
39
40 # Get the database credentials from the config file
41 DATABASE=$(awk '/^DATABASE/ { print substr(substr($3, 2), 0, (length($3) - 2)) }' $confpath)
42 DB_HOST=$(awk '/^DB_HOST/ { print substr(substr($3, 2), 0, (length($3) - 2)) }' $confpath)
43 DB_NAME=$(awk '/^DB_NAME/ { print substr(substr($3, 2), 0, (length($3) - 2)) }' $confpath)
44 DB_USER=$(awk '/^DB_USER/ { print substr(substr($3, 2), 0, (length($3) - 2)) }' $confpath)
45 DB_PASS=$(awk '/^DB_PASS/ { print substr(substr($3, 2), 0, (length($3) - 2)) }' $confpath)
46
47
48 # Build the SQL Delete string
49 TIMESPEC=$(date -u -d "${keeptime} days ago" "+%s")
50 SQL="START TRANSACTION; \
51 DELETE FROM Flows \
52         WHERE TimeStart < ${TIMESPEC}; \
53 COMMIT;"
54
55 # Expire old data
56 if [ "$DATABASE" == "mysql" ]; then
57         echo $SQL | mysql -h $DB_HOST -u$DB_USER -p$DB_PASS $DB_NAME
58 else
59         echo "TODO: pgsql cmdline support"
60 fi
Note: See TracBrowser for help on using the browser.