Advertisement
radeschi

Untitled

Aug 16th, 2012
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.24 KB | None | 0 0
  1. #!/bin/bash
  2. LOG="mail.log.zimbra"
  3. F_ID_FROM="id_from"
  4. F_FROM="campo_from"
  5. DOMINIO="empresa.com.br"
  6.  
  7. function conta_linhas(){
  8.     awk '{
  9.     for (w = 1; w <= NF; w++) conta[$w] ++
  10. }
  11. END {
  12.     for (w in conta) print conta[w], w | "sort -nr"
  13. }' $1
  14. }
  15.  
  16. #Captura ID e campo FROM
  17. cat $LOG | sed -rn '/from=/{s/.*: ([^:]*): from=<([^>]*)>.*/\1 \2/;p};' | grep "$DOMINIO" | grep -v NOQUEUE > $F_ID_FROM
  18. TOTAL_MSG=$(cat $F_ID_FROM | wc -l)
  19.  
  20. #Filtra FROM
  21. cat $F_ID_FROM | cut -d' ' -f2 | cut -d',' -f1 | cut -d'<' -f2 | cut -d'>' -f1 | awk '!i[$0]++' | sed '/^$/d' > $F_FROM
  22. TOTAL_USERS=$(cat $F_FROM | wc -l)
  23.  
  24. #Agrupa mensagens dos usuarios por id
  25. COUNTER=1
  26. while [ $COUNTER -le $TOTAL_MSG ];
  27.     do
  28.         USER_A=$(sed -n $COUNTER' p;' $F_ID_FROM | cut -d' ' -f2)
  29.         ID_A=$(sed -n $COUNTER' p;' $F_ID_FROM | cut -d' ' -f1)
  30.         #echo -ne "> Mensagem: $ID_A \t\t"
  31.         cat $LOG | grep $ID_A >> report/$USER_A.tmp
  32.         cat report/$USER_A.tmp | grep $ID_A | grep to= | cut -d'=' -f2 | cut -d'<' -f2 | cut -d'>' -f1 | awk '!i[$0]++' >> report/$USER_A-remetentes.tmp
  33.         cat report/$USER_A.tmp | cut -d' ' -f1,2,3 | awk '!i[$0]++' >> report/$USER_A-data.tmp
  34.         echo "$COUNTER de $TOTAL_MSG"
  35.         COUNTER=$(($COUNTER+1))
  36. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement