Skip to content

Instantly share code, notes, and snippets.

@BFDZ
Last active November 21, 2017 14:07
Show Gist options
  • Save BFDZ/e3bb50b5f54e22761260c0ef4f977ef0 to your computer and use it in GitHub Desktop.
Save BFDZ/e3bb50b5f54e22761260c0ef4f977ef0 to your computer and use it in GitHub Desktop.
#!/bin/bash
limit=92
dir=/home/bfdz/rtorrent/downloads/
v_mail=
log=/var/log/check_size.log
flag=0
while [ 1 ]
do
v_size=$(df / | grep / | awk '{print $5}' | cut -d '%' -f 1)
if [ $v_size -ge $limit ] && [ $flag -ne 1 ]; then
chmod 555 $dir
echo Lock_the_directory:$dir >> $log && date >> $log
echo "盒子的使用空间超过 $limit%,目录 $dir 已禁止写入." | mail -s "=?UTF-8?B?`echo 盒子剩余空间不足 | base64`?=" $v_mail
flag=1
fi
if [ $v_size -lt $limit ] && [ $flag -ne 0 ]; then
chmod 775 $dir
flag=0
fi
sleep 30
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment