forked from UoE-macOS/jss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoreconfig-check-disk-space.sh
55 lines (40 loc) · 1.75 KB
/
coreconfig-check-disk-space.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
#############################################################################
#
# Script to perform a check on the Mac's available disk space and trigger a
# Yo notification to alert the user if the disk's capacity exceeds 95% or
# there are fewer than 15GB available, whichever comes first.
#
# The latter is the threshold below which operating system upgrades may
# not be successful, so it is best to keep the user informed.
#
#
# Date: Tues 25 Feb 2020 15:23:23 GMT
# Version: 0.1.1
# Creator: ganders1
#
#############################################################################
# Find boot disk name
bootDisk=`diskutil info / | grep "Device Node:" | awk '{print $3}'`
# Find free space percentage
freeSpacePercentage=`df -g | grep "${bootDisk}" | awk '{print $5}' | awk -F "%" '{print $1}'`
echo "The Mac's hard disk is at ${freeSpacePercentage}% capacity."
# Find free space in GB
freeSpaceGB=`df -g | grep "${bootDisk}" | awk '{print $4}'`
echo "There are ${freeSpaceGB}GB free on the Mac."
# Check if disk capacity is greater than 95% or the available free space is below 15GB
spaceStatus=Pass
if [[ ${freeSpacePercentage} -ge 95 ]]; then
spaceStatus=Fail
fi
if [[ ${freeSpaceGB%.*} -le 15 ]]; then
spaceStatus=Fail
fi
if [[ $spaceStatus == Pass ]]; then
/bin/echo "Disk Check: OK - There are either greater than 15GB free on the Mac or the current disk capacity used is below 95%."
else
/bin/echo "Disk Check: ERROR - There are only ${freeSpaceGB}GB free on the Mac or the current disk capacity used is above 95%. Triggering Yo notification on freeing up space."
# Trigger Yo notification on low disk space pointing users to https://edin.ac/mac-low-disk-space
/usr/local/bin/jamf policy -event low-disk-space
fi
exit 0;