-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiskcheck.sh
executable file
·33 lines (29 loc) · 969 Bytes
/
diskcheck.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/sh
# Maintained at: [email protected]:dareni/shellscripts.git
# Send a mail to root when the disk usage passes a threshold.
# Usage: diskcheck.sh [filesystem] [threshold%]
# Usage: diskcheck.sh [filesystem1:filesystem2] [threshold%]
if [ -z "$1" ]; then
FS="/"
else
FS="$1"
fi
if [ -z "$2" ]; then
THRESHOLD=98
else
THRESHOLD=$2
fi
CAP_MSG=""
for FSYS in `echo $FS |sed 's/:/ /g'`
do
CAPACITY=`df ${FSYS} | awk '{ if (NR == 2) print $5}' |sed 's/%//'`
if [ ${CAPACITY} -ge ${THRESHOLD} ]; then
CAP_MSG="${CAP_MSG} $FSYS"
LEN=$((30-${#FSYS}))
CAP_MSG="${CAP_MSG}`printf '%*.*s usage:' 0 $LEN " ....................................."`"
CAP_MSG="${CAP_MSG} $CAPACITY%\n"
fi
done;
if [ -n "$CAP_MSG" ]; then
printf 'WARNING: %s filesystem usage threshold %s exceeded!\n%b' `hostname` ${THRESHOLD} "${CAP_MSG}" | mail -s "`hostname` filesystem usage threshold ${THRESHOLD}% exceeded." root
fi;