[SLUG] bash woes - my turn

From: Mike Branda (mike@wackyworld.tv)
Date: Wed Aug 03 2005 - 15:15:09 EDT


Well our web host uses analog to give stats but it doesn't do unique
visitors. I found a project called "visitors" that does and also
outputs visio style traffic flowcharts. However, they only give me real
apache log files for 5 days. After that all you get is what analog
outputs for up to 2 years I think. So I've started cat-ing the
access.log.0 (the 1 day old logrotate file) to the end of a cumulative
file so I can use visitors. I'm also gzipping the last month's file so
I can conserve as much space as possible. It worked great the last 2
months but now I have the current month's unzipped file, and 2 gzipped
files and my weak attempt at a bash script coughed. It worked great
from a cron job with 1 gz and 1 unzipped. So the issue is that I need
to somehow say for file in access.*.gz (where * is monthly date). Try
not to laugh at this too hard as it's only my second attempt at a bash
script. :^) I built in an else and elif to handle if one of the files
is missing somehow. So the deal is that $file1 is now multiple files.
also keep in mind that evolution is wrapping the long lines.

Any help would be appreciated.

Mike Branda Jr.

#!/bin/bash

home="/home/wws1"
logdir="$home/cumulativelog"
file1="access.log.*.gz"
file2="access.log"
outputfilea="$home/report/index.html"
outputfileb="$home/cumulativelog/graph.dot"
outputfilec="$home/cumulativelog/graphfix.dot"
outputgraph="$home/report/graph.png"
commanda="$home/bin/visitors -A -m 30 -o html -f $outputfilea -"
commandb="$home/bin/visitors -T -V -"
commandc="$home/bin/dot"

if [ -e $logdir/$file1 ] && [ -e $logdir/$file2 ]
then
    echo "starting visitors with both files"
    (gunzip -c $logdir/$file1 && cat $logdir/$file2) | $commanda
    (gunzip -c $logdir/$file1 && cat $logdir/$file2) | $commandb >
$outputfileb
    cat $outputfileb | sed 's/\[splines=true/\[splines=true
fontpath="\/home\/wws1\/fonts\/"/' > $outputfilec
    $commandc $outputfilec -Tpng > $outputgraph
elif [ -e $logdir/$file2 ]
then
    echo "starting visitors with $file2"
    cat $logdir/$file2 | $commanda
    cat $logdir/$file2 | $commandb > $outputfileb
    cat $outputfileb | sed 's/\[splines=true/\[splines=true
fontpath="\/home\/wws1\/fonts\/"/' > $outputfilec
    $commandc $outputfilec -Tpng > $outputgraph
else
    echo "starting visitors with $file1"
    zcat $logdir/$file1 | $commanda
    zcat $logdir/$file1 | $commandb > $outputfileb
    cat $outputfileb | sed 's/\[splines=true/\[splines=true
fontpath="\/home\/wws1\/fonts\/"/' > $outputfilec
    $commandc $outputfilec -Tpng > $outputgraph
fi

-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 19:40:22 EDT