Mini Shell

Direktori : /proc/thread-self/root/proc/thread-self/root/proc/self/root/opt/sharedrads/
Upload File :
Current File : //proc/thread-self/root/proc/thread-self/root/proc/self/root/opt/sharedrads/imap_io

#!/bin/bash
#Written by jeffr - 4/11/12 - Rev 1.0 - jeffr@inmotionhosting.com
#Revised by eriks - 4/26/12 - Rev 1.1 - modified to be in compliance with T3 coding standards

#load functions + banners
source /opt/sharedrads/radsfunctions.sh

if [ "$RADSCOLORS" == "off" ]; then
    radsbanner-nocolor
else
    radsbanner
fi

function HELP()
{
echo
echo "Usage:"
echo "    imap_io [duration] [read rate]"
echo
echo "You can supply two optional arguments to this script."
echo
echo "Arguments:"
echo "    duration  = how long to check for  (minimum/default = 60 seconds)"
echo "    read rate = disk read rate in kbps (minimum/default = 500 kbps)"
echo
}

if [[ $1 == --help ]] || [[ $1 == -h ]]; then
    HELP
    exit 1;
fi


if [ ! -f /usr/bin/iotop ]; then
    echo
    echo " ERROR: iotop is not installed on this system, you cannot use this tool."
    echo
    exit 1;
fi

RUN_FOR_INPUT=$1
if [[ $RUN_FOR_INPUT -gt 60 ]]; then
    RUN_FOR=$RUN_FOR_INPUT
else
    RUN_FOR=60
fi;

THRESHOLD_INPUT=$2
if [[ $THRESHOLD_INPUT -gt 500 ]]; then
    THRESHOLD=$THRESHOLD_INPUT
else
    THRESHOLD=500
fi;

STOP_TIME=$(date +%s --date="$RUN_FOR seconds");

echo
echo " Collecting data from iotop and showing IMAP usage >$THRESHOLD kbps for $RUN_FOR seconds:"
while true; do
    NOW=$(date +%s);
    if [ $NOW -lt $STOP_TIME ]; then
    iodump=`/usr/bin/iotop -qqqkbn1 |awk -v TRANS_RATE="$THRESHOLD" '/imapd/ {if($4 > TRANS_RATE && $3 != "root") print $1"--"$3"--"$4"--"$(NF)}'`
        for sepacct in $iodump; do
        hasvalue=$(echo $sepacct |grep home |wc -l);
        if [ $hasvalue != 0 ]; then
            imapinbox=$(echo $sepacct |awk -F'--' '{print $4}');
            xferrate=$(echo $sepacct |awk -F'--' '{print $3}');
            emailaddy=$(echo $imapinbox |awk -F'/' '{print $6"@"$5}');
            imapfolder=$(echo $sepacct |awk -F'--' '{print $1}' |xargs -i lsof -p{} |tail -1 |awk -F' ' '{print substr($0,index($0,$9)) }' |sed 's%/[^/]*$%/%');
            isinbox=$(echo $imapfolder |grep mail |wc -l);

            if [ $isinbox != 0 ]; then
                num_messages=$(echo "'$imapfolder'" |xargs ls |wc -l);
                echo $emailaddy $num_messages  messages in folder: $imapfolder transferring at a rate of: $xferrate kbps;
            fi;
        fi;
        done;
    else
    exit 0;
    fi;
done

Zerion Mini Shell 1.0