Linux下监控用户磁盘使用量并在超值后发邮件给相应报警
Linux下监控用户磁盘使用量并在超值后发邮件给相应报警
公司虽有磁盘配额设置,但是有些用户经常一个程序跑下来就要吃掉几十个GB的空间,如果使用配额,那在程序运行中,用户空间达到限制时,程序就不能写了,也就崩溃了,因此只能使用软限制,即在发现用户空间达到一定值后给他发邮件让其清理空间
有问题者请加群QQ: 29215534
#!/bin/bash
User_Dir=`ls /cidev/fmnp`
#for i in /cidev/fmnp/*
for i in Algo Backoffice CashEquity Data FICC IBF ITI #用户组目录
do
#du -s /cidev/fmnp/$i/*
if [ -d /cidev/fmnp/$i ];then
du -s /cidev/fmnp/$i/home/* 2>/dev/dull |while read line
do
echo $line | awk '$1 >25000000{print $1,$2}' >> /root/scripts/num.txt #超过25GB报警
done
else
echo $i "is not a directory"
fi
done
mailname=`more /root/scripts/num.txt |awk -F/ '{print $6 }'` #提取用户列表
for mail in $mailname
do
size=`cat /root/scripts/num.txt |awk "/${mail}/{ print $1 }" `
#size2=`cat /root/scripts/num.txt |awk '/${mail}/{ print $2 }' `
content="\n\n Dear ${mail}: \n\n Your Home directory's volume has crossed the waring limit of 25GB,please remove your unimportant data to local disk
ASAP!!! \n\n
The current size of your home directory is : ${size} \n
To locate the big file, you can enter you home directory and then use command find . -size +100M -exec ls -sh {} \; \n "
echo -e $content > /root/scripts/content.txt
echo $size
if [ $mail == "ibf" ];then #如果ibf超值 了,那就把邮件发给 lijie2@ci.com.cn
mail="np_iti_architecture"
mail $mail@ci.com.cn -c lijie2@ci.com.cn -s "Diks Waring" < /root/scripts/content.txt
elif [ $mail == "npbo" ];then
mail=np-trading-backoffice
mail $mail@ci.com.cn -c lijie2@ci.com.cn -s "Diks Waring" < /root/scripts/content.txt
else
mail $mail@ci.com.cn -c lijie2@ci.com.cn -s "Diks Waring" < /root/scripts/content.txt
#echo -e $content > content.txt
echo -e "############################################\n Script running at `date +%F__%H:%M`" >>/var/log/check-disk.log
echo -e "${size} \n sent mail to ${mail}@ci.com.cn " >> /var/log/check-disk.log
fi
done
rm -rf /root/scripts/num.txt
发给用户的邮件内容如下:
Dear maxh: Your Home directory's volume has crossed thewaring limit of 25GB,please remove your unimportant data to local disk ASAP!!! The current size of your home directory is :68506896 /ciccdev/fmnp/Backoffice/home/maxh To locate the big file, you can enter you homedirectory and then use command find . -size +100M -exec ls -sh {} \;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不错!
好东西