#!/usr/local/bin/bash
echo "Attempts,Host,User Names,First Seen,Last Seen" >gropers_ranked.csv; 
toprocess=`wc -l gropers-by-frequency.txt | awk '{print $1}'`
processed=0;
echo "$toprocess hosts to be processed, please wait"
while read gropes groper;
 do 
 grep $groper stripped | grep -v invalid | awk '{print $9}' >stripped.tmp; 
 grep $groper stripped | grep invalid | awk '{print $11}' >>stripped.tmp; 
 groped=`sort -u < stripped.tmp | wc -l`; 
 firstseen=`grep $groper bigauthlog | head -1 | awk '{print $1,$2 " 2012",$3}'`; 
 lastseen=`grep $groper bigauthlog | tail -1 | awk '{print $1,$2 " 2012",$3}'`; 
 echo "$gropes,$groper,$groped,$firstseen,$lastseen" >>gropers_ranked.csv; 
 let "processed++";
 meh=$(($processed % 100));
 if [ "$meh" == "0" ]; then
	echo -n " ... $processed!";
 fi
done < gropers-by-frequency.txt 
echo
echo "$processed hosts processed"
