监控服务器剩余空间脚本:
# vi size.sh
按a或i进入编辑模式
#!/bin/bash
Name=`hostname`
Date=`date +%m%d%y`
Size=`/bin/df -h /home | grep T | awk -F[:" "]+ ‘{print $5}‘`
Size2=`/bin/df -h /home | grep T | awk -F[:" "]+ ‘{print $5}‘ | tr -d ‘%‘`
Size3=`/bin/df -h /home | grep T | awk -F[:" "]+ ‘{print $4}‘`
if [ $Size2 -ge "90" ]
then
touch /log/Size/$Date.log
echo "$Name use size $Size" >> /log/Size/$Date.log
echo "$Name remained size $Size3" >> /log/Size/$Date.log
/usr/bin/mail -s "$Name use size" zhi.ming@ming.com < /log/Size/$Date.log
fi
按Esc键退出编辑模式
:wq (保存并退出)
本文出自 “linux” 博客,谢绝转载!
原文地址:http://yangzhiming.blog.51cto.com/4849999/1430845