Skip to content

Instantly share code, notes, and snippets.

@LuisCardenasSolis
Created March 4, 2021 05:26
Show Gist options
  • Save LuisCardenasSolis/3cb43f553d1cb8deb385d8597929bed9 to your computer and use it in GitHub Desktop.
Save LuisCardenasSolis/3cb43f553d1cb8deb385d8597929bed9 to your computer and use it in GitHub Desktop.
Reporte de mensajes enviados y recibidos - Zimbra
#!/bin/bash
if [ -z $1 ]; then
echo "ERROR: Proporcionar el usuario para le reporte"
exit 1
fi
sender(){
echo "Sender :"
/opt/zimbra/libexec/zmmsgtrace -s "^${1}$" /opt/backup/logs/zimbra.log-202* > /tmp/${1} 2> /dev/null
cat /tmp/${1} | grep Recipient -A2 | grep -Ev '^$|^--$' | grep Recipient -B1 | grep -Ev '^$|^--$' | grep -v Recipient | awk -F' - ' '{print $1}' > /tmp/${1}.date
cat /tmp/${1} | awk '{print $1}' | awk "/Message/,/Recipient/"'{print $0}' | grep -vE "Message|Recipient|${1}@" > /tmp/${1}.to
cat /tmp/${1} | grep Recipient -A3 | grep -Ev '^$|^--$' | grep Recipient -B1 | grep -Ev '^$|^--$' | grep -v Recipient | awk -F' --> ' '{print $2}' > /tmp/${1}.status
tail /tmp/${1} -n2 | head -1 | awk -F' - ' '{print $1}' >> /tmp/${1}.date
tail /tmp/${1} -n2 | head -1 | awk -F' --> ' '{print $2}' >> /tmp/${1}.status
echo "DATE: /tmp/${1}.date"
echo "FROM: ${1}"
echo "TO : /tmp/${1}.to"
echo "STAT: /tmp/${1}.status"
echo "----------------------------------"
}
recipient(){
echo "Recipient :"
/opt/zimbra/libexec/zmmsgtrace -r "^${1}$" /opt/backup/logs/zimbra.log-202* > /tmp/${1}2 2> /dev/null
cat /tmp/${1}2 | grep Recipient -A2 | grep -Ev '^$|^--$' | grep Recipient -B1 | grep -Ev '^$|^--$' | grep -v Recipient | awk -F' - ' '{print $1}' > /tmp/${1}2.date
cat /tmp/${1}2 | grep -E "\-\->$" | awk -F" " '{print $1}' > /tmp/${1}2.from
cat /tmp/${1}2 | grep Recipient -A3 | grep -Ev '^$|^--$' | grep Recipient -B1 | grep -Ev '^$|^--$' | grep -v Recipient | awk -F' --> ' '{print $2}' > /tmp/${1}2.status
tail /tmp/${1}2 -n2 | head -1 | awk -F' - ' '{print $1}' >> /tmp/${1}2.date
tail /tmp/${1}2 -n2 | head -1 | awk -F' --> ' '{print $2}' >> /tmp/${1}2.status
echo "DATE: /tmp/${1}2.date"
echo "FROM: /tmp/${1}2.from"
echo "TO : ${1}"
echo "STAT: /tmp/${1}2.status"
}
sender ${1}
recipient ${1}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment