Howdy all!! First off let me tell you that I'm new to shell
scripting. I have been trying to get the log file from IPTraff to
give me such results as total bytes and bps sent from and to our
dialup & adsl customers as well as our web hosting servers based on
TCP protocols. I'm using the ip_traffic log produced from IPTraf that
looks like this:
Fri May 10 19:18:40 2002; ******** IP traffic monitor started ********
Fri May 10 19:18:40 2002; TCP; eth0; 1500 bytes; from
xxx.xxx.xxx.208:47727 to xxx.xxx.xxx176:25; first packet
Fri May 10 19:18:40 2002; TCP; eth0; 49 bytes; from
xxx.xxx.xxx.162:110 to xxx.xxx.xxx.99:1029; first packet
Fri May 10 19:18:40 2002; TCP; eth0; 40 bytes; from xxx.xxx.xxx.176:25
to xxx.xxx.xxx.208:47727; first packet
Fri May 10 19:18:40 2002; TCP; eth0; 1500 bytes; from
xxx.xxx.xxx.139:80 to xxx.xxx.xxx.233:2162; first packet
The script that I have been working with uses grep and awk since it's
faster that the loops that I started out with even though there are a
lot of lines. (I'll post it below.)
My problem is I can get through the script without errors, but the
results are wacky. Says that the in and out bytes are the same. If
someone could look this over and see what they think that would be
greatly appreciated.
Another question if you don't mind. The standard redirect "cat file1
| awk something > file2" seems to be deleting the info in file1. Is
that what sould be happening? My could worker says not, but ever time
I have run the thing it does.
Again thanks for all you help.
JIM
######################################!/bin/sh
CFGDIR=/usr/local/iptraf/config
DATADIR=/usr/local/iptraf/data
DBDIR=/usr/local/iptraf/db
WEBDIR=/usr/local/iptraf/www
LOGDIR=/var/log/iptraf
DATE=`/bin/date`
#make sure log is present
if test -f $LOGDIR/ip_traffic.log; then
:
else
exit
fi
#create data file for tcp/udp services
/bin/cat $LOGDIR/ip_traffic.log | /bin/sed -e "s/;//g" | /bin/sed -e
"s/:/ /g" | awk '{print $10,$13,$14,$16,$17}' > $LOGDIR/ip_trafficdata
test -f $DATADIR/rentalservers && /bin/rm -f $DATADIR/rentalserversin
test -f $DATADIR/dialup && /bin/rm -f $DATADIR/dialupin
test -f $DATADIR/adsl && /bin/rm -f $DATADIR/adslin
test -f $DATADIR/rentalservers && /bin/rm -f $DATADIR/rentalserversout
test -f $DATADIR/dialup && /bin/rm -f $DATADIR/dialupout
test -f $DATADIR/adsl && /bin/rm -f $DATADIR/adslout
test -f $DATADIR/rentalservershttpout && /bin/rm -f
$DATADIR/rentalservershttpout
test -f $DATADIR/rentalserversftpout && /bin/rm -f
$DATADIR/rentalserversftpout
test -f $DATADIR/rentalserversmailout && /bin/rm -f
$DATADIR/rentalserversmailout
test -f $DATADIR/rentalservershttpin && /bin/rm -f
$DATADIR/rentalservershttpin
test -f $DATADIR/rentalserversftpin && /bin/rm -f
$DATADIR/rentalserversftpin
test -f $DATADIR/rentalserversmailin && /bin/rm -f
$DATADIR/rentalserversmailin
test -f $DATADIR/dialuphttpout && /bin/rm -f $DATADIR/dialuphttpout
test -f $DATADIR/dialupftpout && /bin/rm -f $DATADIR/dialupftpout
test -f $DATADIR/dialupmailout && /bin/rm -f $DATADIR/dialupmailout
test -f $DATADIR/dialuphttpin && /bin/rm -f $DATADIR/dialuphttpin
test -f $DATADIR/dialupftpin && /bin/rm -f $DATADIR/dialupftpin
test -f $DATADIR/dialupmailin && /bin/rm -f $DATADIR/dialupmailin
test -f $DATADIR/adslhttpout && /bin/rm -f $DATADIR/adslhttpout
test -f $DATADIR/adslftpout && /bin/rm -f $DATADIR/adslftpout
test -f $DATADIR/adslmailout && /bin/rm -f $DATADIR/adslmailout
test -f $DATADIR/adslhttpin && /bin/rm -f $DATADIR/adslhttpin
test -f $DATADIR/adslftpin && /bin/rm -f $DATADIR/adslftpin
test -f $DATADIR/adslmailin && /bin/rm -f $DATADIR/adslmailin
/bin/touch $DATADIR/rentalserversout
/bin/touch $DATADIR/rentalserversin
/bin/touch $DATADIR/dialupout
/bin/touch $DATADIR/dialupin
/bin/touch $DATADIR/adslout
/bin/touch $DATADIR/adslin
/bin/touch $DATADIR/rentalservershttpout
/bin/touch $DATADIR/rentalserversftpout
/bin/touch $DATADIR/rentalserversmailout
/bin/touch $DATADIR/rentalservershttpin
/bin/touch $DATADIR/rentalserversftpin
/bin/touch $DATADIR/rentalserversmailin
/bin/touch $DATADIR/dialuphttpout
/bin/touch $DATADIR/dialupftpout
/bin/touch $DATADIR/dialupmailout
/bin/touch $DATADIR/dialuphttpin
/bin/touch $DATADIR/dialupftpin
/bin/touch $DATADIR/dialupmailin
/bin/touch $DATADIR/adslhttpout
/bin/touch $DATADIR/adslftpout
/bin/touch $DATADIR/adslmailout
/bin/touch $DATADIR/adslhttpin
/bin/touch $DATADIR/adslftpin
/bin/touch $DATADIR/adslmailin
if test -f $LOGDIR/ip_trafficdata; then
RS1=`cat $CFGDIR/rentalservers`
for RS2 in $RS1
do
cat $LOGDIR/ip_trafficdata | grep -w $RS2 > $DATADIR/rentalservers
cat $DATADIR/rentalservers | awk '{if($2=RA) print $0}' RA=$RS2 >>
$DATADIR/rentalserversout
cat $DATADIR/rentalservers | awk '{if($4=RA) print $0}' RA=$RS2 >>
$DATADIR/rentalserversin
done
/bin/echo "done pulling out rs data"
DU1=`cat $CFGDIR/dialup`
for DU2 in $DU1
do
cat $LOGDIR/ip_trafficdata | grep -w $DU2 > $DATADIR/dialup
cat $DATADIR/dialup | awk '{if($2=DA) print $0}' DA=$DU2 >>
$DATADIR/dialupout
cat $DATADIR/dialup | awk '{if($4=DA) print $0}' DA=$DU2 >>
$DATADIR/dialupin
done
/bin/echo "done pulling out du data"
ADSL1=`cat $CFGDIR/adsl`
for ADSL2 in $ADSL1
do
cat $LOGDIR/ip_trafficdata | grep -w $ADSL2 > $DATADIR/adsl
cat $DATADIR/adsl | awk '{if($2=DSL) print $0}' DSL=$ADSL2 >>
$DATADIR/adslout
cat $DATADIR/adsl | awk '{if($4=DSL) print $0}' DSL=$ADSL2 >>
$DATADIR/adslin
done
/bin/echo "done pulling out adsl data"
cat $DATADIR/rentalserversin | grep -w 20 >
$DATADIR/rentalserversftp
cat $DATADIR/rentalserversftp | awk '{if($3=="20" || $5=="20") print
$0}' >> $DATADIR/rentalserversftpin
cat $DATADIR/rentalserversout | grep -w 20 >
$DATADIR/rentalserversftp1
cat $DATADIR/rentalserversftp1 | awk '{if($3=="20" || $5=="20")
print $0}' >> $DATADIR/rentalserversftpout
cat $DATADIR/rentalserversin | grep -w 21 >
$DATADIR/rentalserversftp
cat $DATADIR/rentalserversftp | awk '{if($3=="21" || $5=="21") print
$0}' >> $DATADIR/rentalserversftpin
cat $DATADIR/rentalserversout | grep -w 21 >
$DATADIR/rentalserversftp1
cat $DATADIR/rentalserversftp1 | awk '{if($3=="21" || $5=="21")
print $0}' >> $DATADIR/rentalserversftpout
cat $DATADIR/rentalserversin | grep -w 25 >
$DATADIR/rentalserversmail
cat $DATADIR/rentalserversmail | awk '{if($3=="25" || $5=="25")
print $0}' >> $DATADIR/rentalserversmailin
cat $DATADIR/rentalserversout | grep -w 25 >
$DATADIR/rentalserversmail1
cat $DATADIR/rentalserversmail1 | awk '{if($3=="25" || $5=="25")
print $0}' >> $DATADIR/rentalserversmailout
cat $DATADIR/rentalserversin | grep -w 80 >
$DATADIR/rentalservershttp
cat $DATADIR/rentalservershttp | awk '{if($3=="80" || $5=="80")
print $0}' >> $DATADIR/rentalservershttpin
cat $DATADIR/rentalserversout | grep -w 80 >
$DATADIR/rentalservershttp1
cat $DATADIR/rentalservershttp1 | awk '{if($3=="80" || $5=="80")
print $0}' >> $DATADIR/rentalservershttpout
cat $DATADIR/rentalserversin | grep -w 110 >
$DATADIR/rentalserversmail
cat $DATADIR/rentalserversmail | awk '{if($3=="110" || $5=="110")
print $0}' >> $DATADIR/rentalserversmailin
cat $DATADIR/rentalserversout | grep -w 110 >
$DATADIR/rentalserversmail1
cat $DATADIR/rentalserversmail1 | awk '{if($3=="110" || $5=="110")
print $0}' >> $DATADIR/rentalserversmailout
/bin/echo "done pulling out rs protocol data"
cat $DATADIR/dialupin | grep -w 20 > $DATADIR/dialupftp
cat $DATADIR/dialupftp | awk '{if($3=="20" || $5=="20") print $0}'
cat $DATADIR/dialupftp1 | awk '{if($3=="20" || $5=="20") print $0}'
cat $DATADIR/dialupftp | awk '{if($3=="21" || $5=="21") print $0}'
cat $DATADIR/dialupftp1 | awk '{if($3=="21" || $5=="21") print $0}'
cat $DATADIR/dialupmail | awk '{if($3=="25" || $5=="25") print $0}'
cat $DATADIR/dialupmail1 | awk '{if($3=="25" || $5=="25") print $0}'
cat $DATADIR/dialuphttp | awk '{if($3=="80" || $5=="80") print $0}'
cat $DATADIR/dialuphttp1 | awk '{if($3=="80" || $5=="80") print $0}'
cat $DATADIR/dialupmail | awk '{if($3=="110" || $5=="110") print
$0}' >> $DATADIR/dialupmailin
cat $DATADIR/dialupout | grep -w 110 > $DATADIR/dialupmail1
cat $DATADIR/dialupmail1 | awk '{if($3=="110" || $5=="110") print
$0}' >> $DATADIR/dialupmailout
/bin/echo "done pulling out du protocol data"
cat $DATADIR/adslin | grep -w 20 > $DATADIR/adslftp
cat $DATADIR/adslftp | awk '{if($3=="20" || $5=="20") print $0}' >>
$DATADIR/adslftpin
cat $DATADIR/adslout | grep -w 20 > $DATADIR/adslftp1
cat $DATADIR/adslftp1 | awk '{if($3=="20" || $5=="20") print $0}' >>
$DATADIR/adslftpout
cat $DATADIR/adslin | grep -w 21 > $DATADIR/adslftp
cat $DATADIR/adslftp | awk '{if($3=="21" || $5=="21") print $0}' >>
$DATADIR/adslftpin
cat $DATADIR/adslout | grep -w 21 > $DATADIR/adslftp1
cat $DATADIR/adslftp1 | awk '{if($3=="21" || $5=="21") print $0}' >>
$DATADIR/adslftpout
cat $DATADIR/adslin | grep -w 25 > $DATADIR/adslmail
cat $DATADIR/adslmail | awk '{if($3=="25" || $5=="25") print $0}' >>
$DATADIR/adslmailin
cat $DATADIR/adslout | grep -w 25 > $DATADIR/adslmail1
cat $DATADIR/adslmail1 | awk '{if($3=="25" || $5=="25") print $0}'
cat $DATADIR/adslhttp | awk '{if($3=="80" || $5=="80") print $0}' >>
$DATADIR/adslhttpin
cat
...
read more »