backup.sh: Clean up junk if tar creation fails
[mgsautils.git] / host / check-fs-usage.sh
1 #!/bin/sh
2
3 if [ $# -lt 2 ]
4 then
5 echo "Usage: $0 <fs> <percentage> [email]"
6 echo "Where"
7 echo " fs - file system to check"
8 echo " percentage - acceptable file system usage treshold"
9 echo " email - send warning to specified e-mail address (print to stdout, if omitted)"
10 echo "Example: $0 / 95 admin@cutekittens.tld"
11 exit
12 fi
13
14 if [ $(df -m $1 | sed 1d | awk '{print $5}' | sed "s/%//") -ge $2 ]
15 then
16 subject="WARNING! File system usage ($1) on $(hostname) is higher than $2 percent!"
17 if [ -z "$3" ]
18 then
19 echo ${subject}
20 df -m
21 else
22 df -m | mail -s "${subject}" $3
23 fi
24 fi