Last active
July 19, 2023 21:26
-
-
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%.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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