Remove old backups automatically over 86400 mins when disk used over 90% & send mail to named E-mail.

1
2
3
4
5
6
7
8
9
10
SERVER_NAME=\`hostname\`
vvv=\`df -h|awk -F ' ' '{print $5}'|tail -n1\`
len=${#vvv}
newLen=$(( len - 1 ))
num=${vvv:0:newLen}
if \[\[ num -gt 90 \]\]; then
find /path/to/dir -name '*tar.gz' -cmin +86400 -exec rm {} \\;
find /path/to/another/dir -name '*tar.gz' -cmin +86400 -exec rm {} \\;
echo "我们已经使用了 $vvv 空间了注意注意 然后删除了很多文件哦" |mail -s "Disk usage of $SERVER_NAME server" anMail@box.com
fi