Sep
2008
Finding out how many emails were sent/received on a Plesk server
*Edit: Please use this at your own risk. While the script only reports data, I will not be responsible for any issues that may occur with your system if this script is ran. If your not sure if it will work on your server, either don’t use it or run it in a test environment first.
Below is a script that I wrote that reads the mail log file on your server and outputs what email addresses were used in sending/receiving email. It works out quite well on a CentOS5 server w/ Plesk 8.6 and it works in FC6,7 too (although the names of the mail logs don’t show):
#!/bin/bash
maillogdir="/usr/local/psa/var/log"
maillogfiles=`ls -l /usr/local/psa/var/log/|grep maillog.*`
domains=`ls /var/www/vhosts | egrep -v "chroot|default"`
hostname=`hostname`
echo "Choose which mail log you want to review:"
echo "$maillogfiles"|awk '{print $9}'| egrep -v ".bak|.gz|.tar.gz|.tar"
echo -n "Which log file? "; read LOGFILE
maillog="$maillogdir/$LOGFILE"
echo "--------------------------------------------"
echo "Top 10 'From' email addresses:"
cat $maillog | awk '{print $6}'| grep @ | sort | uniq -c | sort -n | grep from= | sed s/from=//g | egrep -v "$domains" | tail -n 10
echo "Top 10 'To' email addresses:"
cat $maillog | awk '{print $6}'| grep @ | sort | uniq -c | sort -n | grep to= | sed s/to=//g |egrep -v "$domains|$hostname" | tail -n 10
echo "--------------------------------------------"
echo -n "Time log starts:";cat $maillog | head -n 1 | awk '{print $1 " " $2 " " $3}'
echo -n "Time log stops:";cat $maillog | tail -n 1| awk '{print $1 " " $2 " " $3}'
I’m sure the code could be cleaner (especially on the output of the email addresses) but the above works. *edit* – I slightly modified the script so that a $hostname variable used. In the above script, I choose to exclude email address that contain my server’s hostname in the ‘To’ addresses, as I’m more concerned with emails getting sent out of my server with this information (as it would indicate that form abuse or similar is taking place on my server).