Skip to content

Instantly share code, notes, and snippets.

@quonic
Last active July 19, 2023 21:26
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 quonic/a274b8f902740d280c5613ce5be342f3 to your computer and use it in GitHub Desktop.
Save quonic/a274b8f902740d280c5613ce5be342f3 to your computer and use it in GitHub Desktop.
MacOS Condition on Low Disk Space. Pass a number such as 90 as an argument, and if the exit code is 1, then a drive is over 90%.
#!/usr/bin/env bash
# MacOS Condition on Low Disk Space. Pass a number such as 90 as an argument, and if the exit code is 1, then a drive is over 90%.
# This exludes any mounted dmg's, USB drives, or cdrom/dvd.
Percentage=$1
IsOver=$(df -H | grep -vE '^Filesystem|tmpfs|cdrom|loop|devfs|map| \/Volumes' | awk '{ print substr($5,1,length($5)-1) }' | awk -v p=$Percentage -F: '{if($1>p){print 1}else{print 0}}' | grep 1 | tail -n1)
exit "$IsOver"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment