Mini Shell
Direktori : /opt/sharedrads/ |
|
Current File : //opt/sharedrads/check_imap |
#!/bin/bash
LINESDEF="120000";
LINES=$LINESDEF
if [ $# -eq 3 ] && [ "$2" == "--lines" ];
then
LINES=$3;
#echo $LINES;
fi
#echo $LINES
function printUsage () {
echo "This script will check /var/log/maillog and active running processes for imap related activity."
echo =Check Mailbox Usage Info=
echo;echo "$0 --topio"
echo "Will show a list of emails with bytes sent and received"
echo;echo "$0 --userconns"
echo "Show a sorted list of active imap processes per user";echo;
echo;echo "$0 --mailbox"
echo "Show a sorted list of active imap processes, sorted per mailbox";echo;
echo;echo "$0 --mboxsize"
echo "Show the size of the mailbox for all connected accounts.";
echo "(could drive the load and take some time - use with care)";echo;
echo =Check Basic Login Info=
echo;echo "$0 --login_email"
echo "Prints the email addresses with the most logins.";echo;
echo;echo "$0 --login_ip"
echo "Prints the IP addresses with the most logins.";echo;
echo;echo "$0 --login_failed"
echo "Prints highest number of failed logins by IP, address, and the both Address and IP.";echo;
echo;echo "$0 --option --lines NUMLINES"
echo "This will execute the option, checking NUMLINES back throgh the log file (default is ${LINESDEF})"
echo;echo "$0 --checkerror";
echo "Checks to see if you are hitting the maximum number allowed connections";
echo "(Use this if you get complaints of pop timing out or being slow to connect!)";
echo;echo "$0 --help"
echo "You're looking at it!"
}
case $1 in
--topio)
tail -${LINES-45000} /var/log/maillog |awk '
/LOGOUT/ && /imapd/ && /user=/{
gsub(/rcvd=/,"",$11);
gsub(/sent=/,"",$12);
rcvd[$7]=rcvd[$7]+$11
sent[$7]=sent[$7]+$12
}
/LOGOUT/ && /pop3d/ && /user=/{
gsub(/sent=/,"",$13);
gsub(/rcvd=/,"",$12);
sent[$7]=sent[$7]+$13
rcvd[$7]=rcvd[$7]+$12
}
END{
for (key in sent) {
printf "%-80s %-10s %-10s\n",key,sent[key],rcvd[key];
}
}'
;;
--userconns)
ps auwx | grep imapd | awk '{if ($1 ~ /[a-z]+[0-9]+/){print $1}; }' | sort | uniq -c | sort -nk1
;;
--mailbox)
ps auwx | grep imapd | awk '{if ($1 ~ /[a-z]+[0-9]+/){print $12}; }' | sort |uniq -c | sort -nk1
;;
--mboxsize)
echo "this may take awhile - hit control-C to exit at any time"
for account in $(ps axuw |
grep "/usr/lib/courier-imap/bin/imapd /home/" |
grep -v root | awk '{ print $12 }'|sort | uniq);
do
du -h --max-depth=0 $account/cur;
done
;;
--login_ip)
tail -${LINES-45000} /var/log/maillog | grep imapd | awk '{print $8}' | sed -e '/^$/d' | sort | uniq -c | sort -nk1
;;
--login_email)
tail -${LINES-45000} /var/log/maillog | grep imapd | awk '/LOGIN/{print $7}' | sort | uniq -c | sort -nk1 | tail -2
;;
--login_failed)
echo "=Sorted by IP="
tail -${LINES-45000} /var/log/maillog | grep imapd |awk '/LOGIN FAILED/{print $9 }' | sort | uniq -c | sort -nk1 | tail -15
echo "=Sorted by Address="
tail -${LINES-45000} /var/log/maillog | grep imapd | awk '/LOGIN FAILED/{print $8 }' | sort | uniq -c | sort -nk1 | tail -15
echo "=Sorted by Address and IP="
tail -${LINES-45000} /var/log/maillog | grep imapd | awk '/LOGIN FAILED/{print $8, $9}' | sort | uniq -c | sort -nk1 | tail -15
;;
--checkerror)
tail -${LINES-45000} /var/log/maillog |grep "maximum active connections";
;;
--help)
printUsage;
exit 0
;;
*)
printUsage;
exit 1
;;
esac
Zerion Mini Shell 1.0