alert-mailtimedelay.sh

暫時無法分類的文章
回覆文章
garyjuang
系統管理員
文章: 32
註冊時間: 2022年 6月 25日, 01:11

alert-mailtimedelay.sh

文章 garyjuang »

代碼: 選擇全部

#!/bin/sh
#mailq delay over 30 mins sent alert mail
#By GaryJuang
#2022-06-14
QFILE=`sendmail -bp -OQueueDirectory=/var/spool/mqueue -OMaxQueueRunSize=1 | head -n 3 | tail -n 1 | awk '{print $1}'`
if [ ${QFILE} = Total ];then
exit
fi
A1=`stat -f %Sm -t "%Y:%m:%d %H:%M:%S" /var/spool/mqueue/df${QFILE}`
A2=`date -j -f "%Y:%m:%d %H:%M:%S" "$A1" +%s`
B=`date +%s`
C=`(expr $B - $A2)`

TO='gary@rcteam.org'
FROM='gary@rcteam.org'
TIME=`date`
#1800 sec = 30 mins
if [ $C -ge 1000 ];then
cat << EOF  | /usr/libexec/sendmail/sendmail.deferred -C/etc/mail/sendmail.deferred.cf -v -f ${FROM} ${TO}
From: ${FROM}
To: ${TO}
Subject: HOST:`hostname` Time: ${TIME}[Queue Delay Over 30 Mins]
Date: ${TIME}
==================== mailq ====================
Detect Time: ${TIME}
==================== mailq ====================
`mailq -OMaxQueueRunSize=10`
==================== maillog ====================
`grep ${QFILE} /var/log/maillog`
==================== milter.log ====================
`grep ${QFILE} /var/log/milter.log`
==================== END ====================
EOF
else
echo $C sec
fi
回覆文章