#!/usr/bin/perl # version: 6 (20020904), Roderik Muit # Script to counter strange behaviour of ipac-ng on my (sparc64, linux-2.4.18) # machine. (See end of script for a description of the problem.) # What it does is go through all files which were created on a certain day # (default: yesterday), and add up the figures from the previous file # to this file. # NOTE: for this script to work correctly, the last file with numbers from the # previous day should be present in $IPACDIR, or the first file from the day # processed should contain correct numbers (which is the case for the first # file produced after 'ipacsum -S') # # The files with 'fixed numbers' are written into another dir ($FIXDIR). # You should run ipacsum with argument '--dir <$FIXDIR>'. # # Do not run this script on a set of data where you did # 'ipacsum -S' (e.g. by restarting the machine) somewhere in that timeframe. # If you stop/start IP accounting, I suggest doing the following: # - stop IP accounting # - run this script to generate all 'fixed' files # - delete the original files (from $IPACDIR), or move them into another # dir (not a subdir of $IPACDIR, or you will probably need to # adjust process_files() below). # Then you can start IP accounting again and return to normal operation (which # is probably, have a cronjob process yesterday's files in /var/lib/ipac before # running ipacsum on /var/lib/ipac-fixed). # usage: $0 [-dw] [date] # -d: print debug output # -w: wait for after each file (not much use without -d) # [date]: date (yyymmdd) of logs to process. Default: yesterday. use strict; use Time::Local; use Getopt::Std; my $IPACDIR = '/var/lib/ipac'; my $FIXDIR = '/var/lib/ipac-fixed'; my $CACHEFILE = '/var/lib/ipacngfix-cache'; # cachefile which will contain numbers from the previous run. # you can set this to '' if you do not want this file to be created, the # script will then get the numbers from the file $FIXDIR/