Skip to content

Commit b468795

Browse files
committed
Add a script for detecting high disk usage
1 parent 0581e1a commit b468795

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

disk-usage.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
3+
# disk-usage.sh - report when disk space starts getting low
4+
5+
# Credit to:
6+
# http://www.cyberciti.biz/faq/mac-osx-unix-get-an-alert-when-my-disk-is-full/
7+
8+
check() {
9+
FS="$1"
10+
OUTPUT=($(LC_ALL=C df -P ${FS}))
11+
CURRENT=$(echo ${OUTPUT[11]} | sed 's/%//')
12+
[ $CURRENT -gt $threshold ] && \
13+
echo "$FS: file system usage at $CURRENT%" && \
14+
return 1
15+
return 0
16+
}
17+
18+
threshold=80
19+
while test $# -gt 0
20+
do
21+
case "$1" in
22+
--threshold|-t)
23+
shift
24+
threshold=$1
25+
;;
26+
*)
27+
check "$1"
28+
;;
29+
esac
30+
shift
31+
done

0 commit comments

Comments
 (0)