Excessive mail sent by an user alert for cPanel

November 11, 2009 | In: Cpanel

If you need a simple script to alert you by mail when a user exceeds a predefined mail rate limit, then check this out.

mailflag=0
limit=5
mailid=mailaddresshere
chkdate=`date -d "60 minute ago" +%Y-%m-%d\ %k`
#chkdate=2009-11-10
mailfile=$(mktemp)
for i in `mysql --batch --skip-column-names -e " use eximstats; select user,email,msgid from sends where \
 mailtime like '$chkdate%';" | awk '{print $1}' | sort | uniq -c | sort -n | sed 's/^ *//'| sed 's/ /:/'`
do
k=`echo $i | cut -d ':' -f1`
username=`echo $i | cut -d ':' -f2`
if [ "$k" -gt "$limit" ]
then
mailflag=1
echo -e "\n\n\n Excessive mail sent by user : $username \n\n" >> $mailfile
echo -e "============================================================================" >> $mailfile
echo "     mailtime           msgid   email   processed       user    size    ip      auth" >> $mailfile
mysql --batch --skip-column-names -e " use eximstats; select * from sends where mailtime like '$chkdate%' and \
user like '$username';" >> $mailfile
echo -e "============================================================================" >> $mailfile
fi
done
if [ "$mailflag" == 1 ]
then
cat $mailfile | mail -s "Excessive mail sent by user" $mailid
fi
rm -rf $mailfile

You need to edit the limit and mailid variables according to your requirement.
eg:
limit=300
mailid=test@live.com

mm
Hi All… I have been working the IT Industry since last ten years… Specialized in Linux, Cloud Infrastructure and Solution Design.
On the hobby friend, I do research on IOT, Micro-controllers, Electronics etc.
Music is my passion..Connect me on..

Comment Form

*

Authors

mm
Presoon John

Hi All... I have been working the IT Industry since last ten years... Specialized in Linux, Cloud Infrastructure and Solution Design.
On the hobby friend, I do research on IOT, Micro-controllers, Electronics etc.
Music is my passion..Connect me on..

Access this post via Mobile

Scan the QR Code
QR Code Generator

Categories