群发quota报警邮件脚本
1、是群发邮件(通过`cat /log/aspera/warn_mail.txt`调用)
2、在邮件内容前增加自定义的3行(sed -e '1i Hi All,':在第1行前增加“Hi All,”;sed -e '2G':在第2行前增加空行)
3、mail -b表示隐藏抄送人,-c不隐藏
#!/bin/bash
Date=`date +%Y%m%d`
Date2=`date +%Y%m%d -d "7 days ago"`
Dir=/aa/shell/Thinclient
/bin/rm -rf $Dir/users_use.txt
/bin/rm -rf $Dir/used.txt
/bin/rm -rf $Dir/warn_$Date2.txt
/bin/touch $Dir/users_use.txt
/bin/touch $Dir/used.txt
/bin/touch $Dir/warn_$Date.txt
ssh 10.0.0.2 "quota report -x" | grep thinclient > $Dir/thinclient.txt
/bin/cat $Dir/thinclient.txt | awk -F[:" "]+ '{print $2}' | grep SPRD > $Dir/users2.txt
sed -i 's/SP/ /g' $Dir/users2.txt
tr -d ' \' $Dir/users.txt
/bin/cat $Dir/users2.txt | tr -d '\' > $Dir/users.txt
for i in `cat $Dir/users.txt`
do
Used=`cat $Dir/thinclient.txt | grep -w $i | awk -F[:" "]+ '{print $5}'`
UsedF=`cat $Dir/thinclient.txt | grep -w $i | awk -F[:" "]+ '{print $8}'`
Usedd=`echo $Used | awk '{$1/=1024*1024;printf "%.0f\n",$1}'`G
Useed=`echo $Used | awk '{$1/=1024*1024;printf "%.0f\n",$1}'`
Total=`cat $Dir/thinclient.txt | grep -w $i | awk -F[:" "]+ '{print $6}'`
TotalF=`cat $Dir/thinclient.txt | grep -w $i | awk -F[:" "]+ '{print $9}'`
Totall=`echo $Total | awk '{$1/=1024*1024;printf "%.0f\n",$1}'`G
Totaal=`echo $Total | awk '{$1/=1024*1024;printf "%.0f\n",$1}'`
Avg=$(($Useed * 100 / $Totaal))%
AvgF=$(($UsedF * 100 / $TotalF))%
/bin/echo $i used:$Usedd,Total:$Totall,Per:$Avg >> $Dir/users_use.txt
/bin/echo $i used:$UsedF,Total:$TotalF,Per:$AvgF >> $Dir/users_use.txt
done
for ii in `cat $Dir/users_use.txt | awk -F[:" "]+ '{print $5}' | tr -d '%'`
do
if [ $ii -gt 80 ];then
/bin/cat $Dir/users_use.txt | grep -w $ii'%' >> $Dir/warn_$Date.txt
fi
done
echo " " >> $Dir/warn_$Date.txt
echo " " >> $Dir/warn_$Date.txt
for iii in `cat $Dir/users_use.txt | awk -F[:" "]+ '{print $9}' | tr -d '%'`
do
if [ $iii -gt 80 ];then
/bin/cat $Dir/users_use.txt | grep -w $iii'%' >> $Dir/warn_$Date.txt
fi
done
/usr/bin/sort -nk 1 $Dir/warn_$Date.txt | uniq > $Dir/warn2_$Date.txt
sed -e 's/$/\r/' $Dir/warn2_$Date.txt > $Dir/warn3_$Date.txt
for I in `cat $Dir/warn3_$Date.txt | awk -F[:" "]+ '{print $1}'`
do
echo $I@ming.com > $Dir/warn_mail.txt
II=`cat $Dir/warn3_$Date.txt | grep $I`
echo $II > $Dir/warn4_$Date.txt
cat $Dir/warn4_$Date.txt | sed -e '1i Hi,' | sed -e '2i your quota of A:(//nas1/thinclient) warn(>80%),please clean' | sed -e '2G' > $Dir/mail_context.txt
/usr/bin/mail -s "$I internal VDI A: quota warn(>80%)" -b zhi.yang@ming.com,zhi.ming@ming.com `cat $Dir/warn_mail.txt` < $Dir/mail_context.txt
本文转自linux博客51CTO博客,原文链接http://blog.51cto.com/yangzhiming/1893016如需转载请自行联系原作者
yangzhimingg