Subject: Ftp log checking script

From: [email-masked] (Koos van den Hout _U nix and we all_)
Date: Thu, 02 Mar 1995 16:29:54 +0000 (WET)

By popular demand ... the script I mentioned. Check it for the correct
places for everything. It does a day. By editing the first awk line (which
takes the wanted day from the ftplog) you can select other time periods.

#!/bin/bash

# Check anonymous-ftp logfile voor incoming anonymous transfers

WEEKDAG=`date +%a`
MAAND=`date +%b`
DAGNUM=`date +%d`

FTPLOG=/var/adm/ftpd/xferlog
TEMPLOG=ftplog.today
RESULT=ftplog.mail
HTMLRESULT=/home/irvdwijk/httpd/htdocs/ftpusage.html

FTPMAINTAINER=koos

awk ' $1=="'$WEEKDAG'" && $2=="'$MAAND'" && $3=="'$DAGNUM'" { print } ' < $FTPLOG > $TEMPLOG

echo "Ftp site usage for `date`" > $RESULT
echo "-------------------------------------------------------------" >> $RESULT
echo "Incoming anonymous files :" >> $RESULT
awk ' $12=="i" && $13=="a" { print } ' < $TEMPLOG >> $RESULT
echo "-------------------------------------------------------------" >> $RESULT
echo "Outgoing anonymous traffic :" >> $RESULT
echo -n "Files : " >> $RESULT
awk ' BEGIN { nfiles=0 } $12=="o" && $13=="a" { nfiles++ } END { print nfiles } ' < $TEMPLOG >> $RESULT
echo -n "Bytes : " >> $RESULT
awk ' BEGIN { nbytes=0 } $12=="o" && $13=="a" { nbytes+=$8 } END { print nbytes } ' < $TEMPLOG >> $RESULT
echo "-------------------------------------------------------------" >> $RESULT
echo "Incoming realuser traffic :" >> $RESULT
echo -n "Files : " >> $RESULT
awk ' BEGIN { nfiles=0 } $12=="i" && $13=="r" { nfiles++ } END { print nfiles } ' < $TEMPLOG >> $RESULT
echo -n "Bytes : " >> $RESULT
awk ' BEGIN { nbytes=0 } $12=="i" && $13=="r" { nbytes+=$8 } END { print nbytes } ' < $TEMPLOG >> $RESULT
echo "-------------------------------------------------------------" >> $RESULT
echo "outgoing realuser traffic :" >> $RESULT
echo -n "Files : " >> $RESULT
awk ' BEGIN { nfiles=0 } $12=="o" && $13=="r" { nfiles++ } END { print nfiles } ' < $TEMPLOG >> $RESULT
echo -n "Bytes : " >> $RESULT
awk ' BEGIN { nbytes=0 } $12=="o" && $13=="r" { nbytes+=$8 } END { print nbytes } ' < $TEMPLOG >> $RESULT
echo "-------------------------------------------------------------" >> $RESULT

mail -s "FTP server usage report" $FTPMAINTAINER < $RESULT > /dev/null
rm -f $RESULT

cat > $HTMLRESULT << EOF
<HTML>
<HEAD>
<TITLE>FTP server usage report</TITLE>
</HEAD>
<BODY>
EOF
echo "<H1>FTP server usage report for " `date` "</H1>" >> $HTMLRESULT
cat >> $HTMLRESULT << EOF
<HR>
<H2>Incoming anonymous traffic :</H2>
EOF
echo -n "Files : " >> $HTMLRESULT
awk ' BEGIN { nfiles=0 } $12=="i" && $13=="a" { nfiles++ } END { print nfiles } ' < $TEMPLOG >> $HTMLRESULT
echo "<BR>" >> $HTMLRESULT
echo -n "Bytes : " >> $HTMLRESULT
awk ' BEGIN { nbytes=0 } $12=="i" && $13=="a" { nbytes+=$8 } END { print nbytes } ' < $TEMPLOG >> $HTMLRESULT
echo "<BR>" >> $HTMLRESULT
cat >> $HTMLRESULT << EOF
<HR>
<H2>Outgoing anonymous traffic :</H2>
EOF
echo -n "Files : " >> $HTMLRESULT
awk ' BEGIN { nfiles=0 } $12=="o" && $13=="a" { nfiles++ } END { print nfiles } ' < $TEMPLOG >> $HTMLRESULT
echo "<BR>" >> $HTMLRESULT
echo -n "Bytes : " >> $HTMLRESULT
awk ' BEGIN { nbytes=0 } $12=="o" && $13=="a" { nbytes+=$8 } END { print nbytes } ' < $TEMPLOG >> $HTMLRESULT
echo "<BR>" >> $HTMLRESULT
cat >> $HTMLRESULT << EOF
<HR>
<H2>Most ftp-ed anonymous files:</H2>
<PRE>
EOF
awk ' $12=="o" && $13=="a" { print $9 } ' < $FTPLOG | sort | uniq -c | sort -nr >> $HTMLRESULT
cat >> $HTMLRESULT << EOF
</PRE>
<HR>
wu-ftp-log 2 html conversion script by Koos van den Hout.<P>
<A HREF="http://www.hvu.nl/~koos/">Go To</A> my homepage.
</BODY>
</HTML>
EOF
rm -f $TEMPLOG
# End of script

-- 
| Koos van den Hout,     Unixer, Internetter                    and BBS SysOp |
| Home:[email-masked]      BBS Koos z'n Doos (+31-3402-36647 28k8 vfc) |
| Work:[email-masked] * finger [email-masked] for PGPkey * (+31-3402-56619 14k4) |
| URL: http://www.hvu.nl/users/koos  I'm looking for a lic.plate with RFC 822 |
|   GCS d- p(-) c++(+++) l+ u+++ e++ m+(-) s+/- !n h f+ g+ w(++) t+ r !y(*)   |