UnixServerAdmin

Server Administration & Management

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.

#######################################################################
#!/bin/bash
mailflag=0
limit=5
mailid=unixserv@unixserveradmin.com
chkdate=`date -d “60 minute ago” +%Y-%m-%d %k`
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 “nnn Excessive mail sent by user : $username nn” >> $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=unixserv@unixserveradmin.com
#######################################################################

Advertisements

August 9, 2011 - Posted by | cPanel, Exim, Shell Script | , ,

1 Comment »

  1. I liked your article is an interesting technology
    thanks to google I found you

    Comment by google | September 3, 2011 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: