Skip to content

Instantly share code, notes, and snippets.

@ormaaj
Created November 14, 2012 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ormaaj/4071150 to your computer and use it in GitHub Desktop.
Save ormaaj/4071150 to your computer and use it in GitHub Desktop.
filesystem size example
#!/bin/bash
# GNU stat(1) required!
typeset -a filesystems
disk_space_threshold=85
hsummary=
filesystems=(/ /DB-Backup)
function checkFS {
typeset fs=
typeset -i fspct=
for fs; do
if [[ -e "$fs" ]]; then
fspct=$(stat -fc "(%a*100)/%b" "$fs") || return 1
if (( (100 - fspct) > disk_space_threshold )); then
LC_TIME=C printf '%(%a %b %e %H:%M:%S %Z %Y)T\t** Low Disk Space **\t on %s' -1 "$fs"
fi
else
return 1
fi
done
}
if ! checkFS "${filesystems[@]}" >>"$hsummary"; then
echo "Error in checkFS" >&2
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment