|
|
Penguins Unbound > Past Meetings > 20110730 - Bash Programming > Shell Scripting (or old *nix tools) > Example Scripts > watch queue.sh
watch queue.shTable of contentsNo headersThis script I use to keep an eye on our mail server. #!/opt/csw/bin/bash
# Copyright 2011 Brian Dolan-Goecke
VERSION="0.0.1 BD-G-20110601"
# Contact me at http://www.goecke-dolan.com/Brian/sendmeail.php
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# We want this to run for ever
LQCNT=0
HIST="."
if test $EUID -ne 0
then
echo "You must be root to run this script"
exit 2
fi
while true
do
# Count how man in the queue
QCNT=`ls -1 /spare1/mqueue/qf* | wc -l`
# Display Queue Count Info
#Filesystem size used avail capacity Mounted on
#/dev/md/dsk/d14 9.6G 2.7G 6.9G 28% /
#/dev/md/dsk/d11 9.6G 2.8G 6.7G 30% /usr
#/proc 0K 0K 0K 0% /proc
#mnttab 0K 0K 0K 0% /etc/mnttab
#fd 0K 0K 0K 0% /dev/fd
#/dev/md/dsk/d8 9.6G 1.7G 7.8G 18% /var
#swap 8.5G 56K 8.5G 1% /var/run
#swap 8.6G 101M 8.5G 2% /tmp
#/dev/md/dsk/d0 9.6G 3.5G 6.1G 37% /logs
#/dev/md/dsk/d17 28G 19G 8.0G 71% /spare1
#/dev/md/dsk/d20 66G 63G 2.6G 96% /export
#/dev/md/dsk/d5 66G 63G 3.1G 96% /var/mail
#swap 8.5G 0K 8.5G 0% /tmpfs
#/dev/md/dsk/d5 66G 63G 1000K 96% /var/mail
#1234567890123456789012345678901234567890123456789012345678901234567890
# 1 2 3 4 5 6 7
clear
MAIL_DISK_FREE=`df -h | grep mail | cut -c36-41`
HOME_DISK_FREE=`df -h | grep export | cut -c36-41`
echo -e "mail free: $MAIL_DISK_FREE export free: $HOME_DISK_FREE\t\c"
DATE=`date`
# echo -n "$DATE "
echo "$DATE "
# okay to cut crap out of the uptime you have to really screw around
#because its formating changes based on name and number of user loged in arg
# 1:09pm up 489 day(s), 14:45, 1 user, load average: 1.82, 1.90, 1.91
# 1:24pm up 489 day(s), 14:59, 2 users, load average: 2.35, 2.18, 2.05
# 11:42am up 490 day(s), 13:17, 2 users, load average: 2.38, 2.15, 2.11
# so for now not going to mess with it.
# uptime | cut -d\ -f6,15,16,17
echo "- QUEUE Count -------------------------------------------------------------------"
echo -e "Q Count: $QCNT \c"
if test $LQCNT -gt $QCNT
then
diff_size=`expr $LQCNT - $QCNT`
if test $diff_size -gt 100
then
char="V"
else
char="v"
fi
echo -e "\033[32m $char dn\033[0m $HIST"
HIST=`echo "$char$HIST"`
else
if test $LQCNT -lt $QCNT
then
diff_size=`expr $QCNT - $LQCNT`
if test $diff_size -gt 100
then
char="A"
else
char="^"
fi
if test $diff_size -gt 100
then
echo -e "\033[5;31m $char up\033[0m $HIST"
else
echo -e "\033[31m $char up\033[0m $HIST"
fi
HIST=`echo "$char$HIST"`
else
echo -e "= sm $HIST"
HIST=`echo "=$HIST"`
fi
fi
HIST=`echo $HIST | cut -c1-60`
cd /spare1/mqueue
QUARCNT=`ls -1 hf* 2>/dev/null | wc -l`
if test $QUARCNT -gt 1
then
echo -e "\033[31m\c"
echo -e "** $QUARCNT QUARANTIED FILES **************************************************\c"
echo -e "\033[0m"
fi
cd /spare1/mqueue
echo "- TOP TO Domains ----------------------------------------------------------------"
grep "^H??To: " qf* | cut -d\: -f3 | cut -d\@ -f2 | sort | uniq -c | sort -r | head -5
echo "- TOP TO ------------------------------------------------------------------------"
# to by domain
grep "^H??To: " qf* | cut -d\: -f3 | sort | uniq -c | sort -r | head -15
echo "- FROM --------------------------------------------------------------------------"
# from by user@domain
grep "^H??From: " qf* | cut -d\: -f3 | sort | uniq -c | sort -r | head -15
# Prep to end of loop
# sleep than retry
echo
uptime
sleep 60
LQCNT=$QCNT
done
|