Archive

Archive for the ‘awk’ Category

Count domain in mail.log (Qmail)

February 20th, 2009

 Powered by Max Banner Ads 
# cat /usr/local/sbin/count_mail_per_domain.sh
#!/bin/bash
logfile=$2
domain=$3
 
case "$1" in
        -t)
	cat $logfile |grep "to remote" | awk '{print $14}'
					| awk -F@ '{ field = $2 }; {print "domain: " field }'
					| sort |uniq -c |sort -nr
					| awk -v totale=0 '{totale=totale+$1; print ;} END {print "Totale giorno domini: "totale;}'
            ;;
 
        -su)
	cat $logfile |grep "to remote"  |grep -i "$domain"
					|awk ' { field = $14 }; {print "to remote: " field }'
					| sort| uniq -c| sort -nr
					| awk -v totale=0 '{totale=totale+$1; print ;} END {print "Totale giorno domini per utente: "totale;}'
            ;;
	-s)
        cat $logfile |grep "to remote"  |grep -i "$domain" |awk '{print $14}'
                                        | awk -F@ '{ field = $2 }; {print "to remote domain: " field }'
                                        | sort| uniq -c| sort -nr
                                        | awk -v totale=0 '{totale=totale+$1; print ;} END {print "Totale giorno domini: "totale;}'
 
         ;;
        *)
            echo $"Usage: $0 { -t /var/log/mail.log.0 }  for print total mail for domain "
            echo $"Usage: $0 { -su /var/log/mail.log.0 domain.com } for print total mail for single domain per user"
            echo $"Usage: $0 { -s /var/log/mail.log.0 domain.com } for print total mail for single domain"
            exit 1
 
esac

for more tips visit qmail relay to smarthost

Fabio Laganà Debian, Mailserver, Qmail, Shell, Uncategorized, awk, bash , , , , ,

tips&tricks

March 25th, 2008

# last filed

zcat access.log.gz |grep 27/Jan/2008 |awk '{ field = $NF }; {print field}'

# count per Hits

zcat access.log.gz  |grep 27/Jan/2008 |awk '{ field = $NF }; {print "Host: " field } ' | sort |uniq -c

# count per Hits + Totale al fondo

cat nomefile |grep "27/Jan/2008:" |awk ' { field = $NF }; {print "Host: " field }' | sort|uniq -c|sort -nr|awk -v totale=0 '{totale=totale+$1; print ;} END {print "Totale giornaliero: "totale;}'

Fabio Laganà awk, bash