监控服务器剩余空间脚本:
# 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" [email protected] < /log/Size/$Date.log
fi
按Esc键退出编辑模式
:wq (保存并退出)
监控服务器剩余空间脚本
时间: 2024-10-22 10:33:25