Skip to content

Commit

Permalink
Merge pull request #183 from SpookOz/main
Browse files Browse the repository at this point in the history
Create Mac-Install_diskspace
  • Loading branch information
silversword411 authored Sep 22, 2023
2 parents 78f1df1 + 46d35f2 commit 060fec1
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
36 changes: 36 additions & 0 deletions scripts_wip/Mac-Check-Free-Disk-Space.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash

# Gets accurate disk usage measurements on a Mac using diskspace utility and warns if space is getting low
# Exit code of 2 when space is getting low. Exit code of 1 when space is critically low.

# https://github.com/scriptingosx/diskspace
# https://scriptingosx.com/2021/11/monterey-python-and-free-disk-space/

# Note: The ‘Available’ value matches the actually unused disk space that df and diskutil will report. The ‘Important’ value matches what Finder will report as available. The ‘Opportunistic’ value is somewhat lower, and from Apple’s documentation on the developer page, that seems to be what we should use for automated background tasks.

# Variables - Change to match your needs
lowspace=10000000000
criticalspace=5000000000

# Install diskspace utility if not already installed
if [ ! -f /usr/local/bin/diskspace ]
then
echo "diskspace utility not found. Installing."
curl -k -L -o /tmp/diskspace-1.pkg "https://github.com/scriptingosx/diskspace/releases/download/v1/diskspace-1.pkg"
sudo installer -pkg /tmp/diskspace-1.pkg -target /
fi

# Check Disk space
if [[ $(/usr/local/bin/diskspace --important ) -gt $lowspace ]]; then
echo "Disk space OK:"
/usr/local/bin/diskspace -H
exit 0
elif [[ $(/usr/local/bin/diskspace --important ) -gt $criticalspace ]]; then
echo "Disk space getting low:"
/usr/local/bin/diskspace -H
exit 2
else
echo "Warning: Disk space critically low:"
/usr/local/bin/diskspace -H
exit 1
fi
11 changes: 11 additions & 0 deletions scripts_wip/Mac-Install_diskspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
# Get accurate disk usage measurements on a Mac
# https://github.com/scriptingosx/diskspace
# https://scriptingosx.com/2021/11/monterey-python-and-free-disk-space/

# Download package and install
curl -k -L -o /tmp/diskspace-1.pkg "https://github.com/scriptingosx/diskspace/releases/download/v1/diskspace-1.pkg"
sudo installer -pkg /tmp/diskspace-1.pkg -target /

# Run to test
/usr/local/bin/diskspace -H
8 changes: 7 additions & 1 deletion scripts_wip/Mac_Users_List.sh
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
/usr/bin/dscl . -list /Users
#!/usr/bin/env bash

# Old code
# /usr/bin/dscl . -list /Users

# New code to list Mac users and filters out the system users
/usr/bin/dscl . -list /Users | grep -v '^_'

0 comments on commit 060fec1

Please sign in to comment.