Parse disk space using df -P -k.

This commit is contained in:
Daniel Nichter
2011-12-19 10:22:42 -07:00
parent a172a3f2a7
commit bb315948cd
3 changed files with 38 additions and 27 deletions

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash
TESTS=10
TESTS=11
source "$LIB_DIR/log_warn_die.sh"
source "$LIB_DIR/safeguards.sh"
@@ -13,30 +13,35 @@ cmd_ok \
"grep -q Avail $TMPDIR/df-out" \
"disk_space()"
check_disk_space "$SAMPLE/diskspace001.txt" 22495 18 >$TMPDIR/out 2>&1
is \
"`wc -l $TMPDIR/df-out | awk '{print $1}'`" \
"2" \
"2-line df output"
check_disk_space "$SAMPLE/diskspace001.txt" 22000 18 >$TMPDIR/out 2>&1
is "$?" "0" "Enough disk space"
is \
"`cat $TMPDIR/out`" \
"" \
"No output if enough disk space"
check_disk_space "$SAMPLE/diskspace001.txt" 22496 18 >$TMPDIR/out 2>&1
check_disk_space "$SAMPLE/diskspace001.txt" 24000 18 >$TMPDIR/out 2>&1
is "$?" "1" "Not enough MB free"
cmd_ok \
"grep -q '19% free, 22496 MB free; wanted more than 18% free or 22496 MB free' $TMPDIR/out" \
"grep -q '19% free, 23487512 KB free; wanted more than 18% free or 24576000 KB free' $TMPDIR/out" \
"Warning if not enough disk space"
check_disk_space "$SAMPLE/diskspace001.txt" 22495 19 >$TMPDIR/out 2>&1
check_disk_space "$SAMPLE/diskspace001.txt" 22000 19 >$TMPDIR/out 2>&1
is "$?" "1" "Not enough % free"
# ###########################################################################
# Check with a margin (amount we plan to use in the future).
# ###########################################################################
check_disk_space "$SAMPLE/diskspace001.txt" 22395 18 100
check_disk_space "$SAMPLE/diskspace001.txt" 22000 18 100
is "$?" "0" "Enough disk space with margin"
check_disk_space "$SAMPLE/diskspace001.txt" 22396 18 100 >$TMPDIR/out 2>&1
check_disk_space "$SAMPLE/diskspace001.txt" 23000 18 100 >$TMPDIR/out 2>&1
is "$?" "1" "Not enough MB free with margin"
check_disk_space "$SAMPLE/diskspace001.txt" 100 5 20000 >$TMPDIR/out 2>&1