Excessive mail sent by an user alert for 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.

========================================================================

1# mailflag=0
2# limit=5
3# mailid=mailaddresshere
4# chkdate=`date -d “60 minute ago” +%Y-%m-%d\ %k`
5# #chkdate=2009-11-10
6# mailfile=$(mktemp)
7# for i in `mysql –batch –skip-column-names -e ” use eximstats; select user,email,msgid from sends where \
8# mailtime like ‘$chkdate%’;” | awk ‘{print $1}’ | sort | uniq -c | sort -n | sed ’s/^ *//’| sed ’s/ /:/’`
9# do
10# k=`echo $i | cut -d ‘:’ -f1`
11# username=`echo $i | cut -d ‘:’ -f2`
12i# f [ "$k" -gt "$limit" ]
13# then
14# mailflag=1
15# echo -e “\n\n\n Excessive mail sent by user : $username \n\n” >> $mailfile
16# echo -e “==============================================================
===========” >> $mailfile
17# echo “ mailtime msgid email processed user size ip auth” >> $mailfile
18# mysql –batch –skip-column-names -e ” use eximstats; select * from sends where mailtime like ‘$chkdate%’ and \
19# user like ‘$username’;” >> $mailfile
20# echo -e “===============================================================
========” >> $mailfile
21# fi
21# done
22# if [ "$mailflag" == 1 ]
23# then
24# cat $mailfile | mail -s “Excessive mail sent by user” $mailid
25# fi
26# rm -rf $mailfile
==========================================================================

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

Suggestions, questions are welcome.

    1 comments:

  1. How this will work? we need to run this script each time ryt?