Skip to content

Instantly share code, notes, and snippets.

@rahulinux
Last active December 21, 2015 21:29
Show Gist options
  • Save rahulinux/6368248 to your computer and use it in GitHub Desktop.
Save rahulinux/6368248 to your computer and use it in GitHub Desktop.
Check disk spce , if disk space (Example /home = 90 %) then return 1 if no partition specified then it will check each partition
function CheckSpace() {
local Partition=$1
awk -v p=$Partition 'BEGIN{
threshold=80
cmd = "LC_ALL=C df -Ph "p
while( cmd | getline ) {
used=$5 # Usage in % of 5th colume
if ( $1 != "Filesystem" && int(used) >= threshold ) {
exit 1
}
}
}'
}
CheckSpace $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment