forked from ckujau/nagios-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_dirsize.sh
executable file
·42 lines (35 loc) · 944 Bytes
/
check_dirsize.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
34
35
36
37
38
39
40
41
42
#!/bin/sh
#
# (c)2015 Christian Kujau <lists@nerdbynature.de>
# Check on the size of a directory
#
usage() {
echo "Usage: $0 [-w KB] [-c KB] [-d <directory>]"
exit 3
}
while getopts "w:c:d:h" opt; do
case $opt in
w) warn=${OPTARG} ;;
c) crit=${OPTARG} ;;
d) dir=${OPTARG} ;;
h) usage ;;
*) usage ;;
esac
done
# Sanity checks
[ -z "$warn" ] || [ -z "$crit" ] || [ ! -d "$dir" ] && usage
# FIXME: Can we make the call to du(1) portable across multiple platforms?
SIZE=$(du -skx "$dir" 2>/dev/null | awk '{print $1}')
if [ "$SIZE" -le "$crit" ]; then
echo "CRITICAL: directory $dir is smaller than $crit KB! ($SIZE KB)"
exit 2
elif [ "$SIZE" -le "$warn" ]; then
echo "WARNING: directory $dir is smaller than $warn KB! ($SIZE KB)"
exit 1
elif [ "$SIZE" -gt "$warn" ]; then
echo "OK: directory $dir is big enough. ($SIZE KB)"
exit 0
else
echo "UNKNOWN: directory $dir has an unknown size: $SIZE KB"
exit 3
fi