-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathcoreconfig-softwareupdate-recon-reboot
61 lines (51 loc) · 1.74 KB
/
coreconfig-softwareupdate-recon-reboot
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
56
57
58
59
60
61
#!/bin/bash
##################################################################
#
# Check the 'last' log for a reboot and perform a recon if a SUDONE
# flag file has been generated by the softwareupdate policy on or
# around the same day.
#
# Date: Tue 7 Jan 2020 14:37:30 GMT
# Version: 0.1.2
# Creator: dsavage
#
##################################################################
containsElement () {
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && echo 0; done
echo 1
}
# Get the OS on the Mac
OS_Version=$( sw_vers -productVersion )
# Check if the OS matches our logged one, do a recon if it doesn't.
if [ -f /Library/MacSD/os_version ]; then
Recorded_Version=$( cat /Library/MacSD/os_version )
if ! [ ${Recorded_Version} == ${OS_Version} ]; then
/usr/local/bin/jamf recon
echo ${OS_Version} > /Library/MacSD/os_version
rm -f /Library/MacSD/SUDONE
else
echo "This Mac has rebooted but no softwareupdate flag file or OS change found. No recon necessary."
fi
else
echo ${OS_Version} > /Library/MacSD/os_version
fi
# Look in the last log for a reboot in the last 20 entries and feed into array.
Reboot_Array=( `last -20 | grep reboot | awk '{print $4$5}'` )
# Get the day/month for today.
Day_Today=$( date "+%b%d" )
# Check if the array contains Day_Today
Day_Match=$( containsElement "${Day_Today}" "${Reboot_Array[@]}" )
# Check for the SUDONE file, if it exists perform a recon
if ! [ "${Day_Match}" == "1" ]; then
if [ -f /Library/MacSD/SUDONE ]; then
echo "This Mac has rebooted after a softwareupdate, performing recon."
/usr/local/bin/jamf recon
echo "Removing SU flag file."
rm -f /Library/MacSD/SUDONE
else
echo "This Mac has rebooted but no softwareupdate flag file found. No recon necessary."
fi
fi
exit 0;