Home Hosters Blog Was macht der FTP Server?

Was macht der FTP Server? Drucken

Was passiert auf meinem FTP-Server? Wir stellen hier ein kleines Bash-Script vor, das die xfer.log Datei eines FTP Server ausliest und die Ergebnisse auf der stdn ausgibt.

Legen Sie zuerst 2 Dateien an. Nennen Sie die Dateien z.B. xferlog.sh und nicenumber


-------------------------------------------------------------------------------------
nicenumber

#!/bin/sh


nicenumber()
{
integer=$(echo $1 | cut -d. -f1)
decimal=$(echo $1 | cut -d. -f2)

if [ $decimal != $1 ]; then
# there's a fractional part, let's include it.
result="${DD:="."}$decimal"
fi

thousands=$integer

while [ $thousands -gt 999 ]; do
remainder=$(($thousands % 1000))

while [ ${#remainder} -lt 3 ] ; do
remainder="0$remainder"
done

thousands=$(($thousands / 1000))
result="${TD:=","}${remainder}${result}" 
done

nicenum="${thousands}${result}"
if [ ! -z $2 ] ; then
echo $nicenum
fi
}

DD="." 
TD="," 

while getopts "d:t:" opt; do
case $opt in
d ) DD="$OPTARG"    ;;
t ) TD="$OPTARG"    ;;
esac
done

shift $(($OPTIND - 1))

if [ $# -eq 0 ] ; then
cat << "EOF" >&2
Usage: $(basename $0) [-d c] [-t c] numeric value
-d specifies the decimal point delimiter (default '.')
-t specifies the thousands delimiter (default ',')
EOF
exit 1
fi

nicenumber $1 1

exit 0

---------------------------------------------------------------------------

xferlog.sh

#!/bin/sh

stdxferlog="/var/log/vsftpd.log"   ## Name and PAth to your xferlog file
temp="/tmp/$(basename $0).$$"
nicenum="$HOME/SCRIPTS/nicenumber"

trap "/bin/rm -f $temp" 0

extract()
{
# called with $1 = desired accessmode, $2 = section name for output

if [ ! -z "$(echo $accessmode | grep $1)" ] ; then

echo "" ; echo "$2"

if [ "$1" = "a" -o "$1" = "g" ] ; then
echo "  common account (entered password) values:"
else
echo "  user accounts accessing server: "
fi
awk "\$13 == \"$1\" { print \$14 }" $log | sort | \
uniq -c | sort -rn | head -10 | sed 's/^/    /'

awk "\$13 == \"$1\" && \$12 == \"o\" { print \$9 }" $log | sort | \
uniq -c | sort -rn | head -10 | sed 's/^/    /' > $temp
if [ -s $temp ] ; then
echo "  files downloaded from server:" ; cat $temp
fi

awk "\$13 == \"$1\" && \$12 == \"i\" { print \$9 }" $log | sort | \
uniq -c | sort -rn | head -10 | sed 's/^/    /' > $temp

if [ -s $temp ] ; then
echo "  files uploaded to server:" ; cat $temp
fi
fi
}


###### the main script block

case $# in
0 ) log=$stdxferlog           ;;
1 ) log="$1"                  ;;
* ) echo "Usage: $(basename $0) {xferlog name}" >&2
exit 1
esac

if [ ! -r $log ] ; then
echo "$(basename $0): can't read $log." >&2
exit 1
fi


if [ ! -z $(awk '$6 == "get" { short=1 } END{ print short }' $log) ] ; then
bytesin="$(awk 'BEGIN{sum=0} $6 == "get" {sum += $9} END{ print sum }' $log )"
bytesout="$(awk 'BEGIN{sum=0} $6 == "put" {sum += $9} END{ print sum }' $log )"

echo -n "Abbreviated ftpd xferlog from "
echo -n $(head -1 $log | awk '{print $1, $2, $3 }')
echo    " to $(tail -1 $log | awk '{print $1, $2, $3}')"
echo "       bytes in: $($nicenum $bytesin)"
echo "      bytes out: $($nicenum $bytesout)"
exit 0
fi

bytesin="$(awk 'BEGIN{sum=0}   $12 == "i" {sum += $8} END{ print sum }' $log )"
bytesout="$(awk 'BEGIN{sum=0} $12 == "o" {sum += $8} END{ print sum }' $log )"
time="$(awk 'BEGIN{sum=0} {sum += $6} END{ print sum }' $log)"

echo -n "Summary of xferlog from "
echo -n $(head -1 $log | awk '{print $1, $2, $3, $4, $5 }')
echo    " to $(tail -1 $log | awk '{print $1, $2, $3, $4, $5}')"
echo "       bytes in: $($nicenum $bytesin)"
echo "      bytes out: $($nicenum $bytesout)"
echo "  transfer time: $time seconds"

accessmode="$(awk '{print $13}' $log | sort -u)"

extract "a" "Anonymous Access"
extract "g" "Guest Account Access"
extract "r" "Real User Account Access"

exit 0


-----------------------------------------------------------------------------------------------------------



Mehr Informationen über das xferlog-System finden Sie hier:
http://aolserver.am.net/docs/2.3/ftp-ch4.htm

 

 

 

Kontakt
Impressum
AGB
Datenschutz
DomainAutomat 
Joomla-Hosting24 
German-Congress-Group 
Isp4you Software 
Joomla Hosting
Typo3 Hosting
Wordpress Hosting
 © 2010 by Provider4u GmbH
Alle Preise inkl. 19% MwSt.

 

 




 
 


Joomla Best Price Hosting Joomla Webhosting Joomla Hosting Joomla Webhosting Joomla Hosting serving deutschen bundestag fairprice garantie