-
Notifications
You must be signed in to change notification settings - Fork 28
/
check_ad_jss.sh
49 lines (34 loc) · 1.45 KB
/
check_ad_jss.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
#!/bin/bash
# Variables
apiURL="https://your.jss.com:8443"
apiUser="EA_API_USER"
apiPass="EA_API_PASSWORD"
###### Do not edit below this line
dscacheutil -flushcache
sleep 5
# Check if the computer is on the network by reading its own computer object from AD
# Get Domain from full structure, cut the name and remove space.
ShortDomainName=`dscl /Active\ Directory/ -read . | grep SubNodes | sed 's|SubNodes: ||g'`
computer=$(dsconfigad -show | grep "Computer Account" | awk '{ print $4 }')
dscl /Active\ Directory/$ShortDomainName/All\ Domains -read /Computers/$computer RecordName &>/dev/null
if [ ! $? == 0 ] ; then
result="No connection to the domain"
exit 1
else
result="Connected to $ShortDomainName"
fi
# Upload result of AD connection test
echo "<computer>" > /private/tmp/EA.xml
echo " <extension_attributes>" >> /private/tmp/EA.xml
echo " <extension_attribute>" >> /private/tmp/EA.xml
echo " <name>AD Connection Status</name>" >> /private/tmp/EA.xml
echo " <value>$result</value>" >> /private/tmp/EA.xml
echo " </extension_attribute>" >> /private/tmp/EA.xml
echo " </extension_attributes>" >> /private/tmp/EA.xml
echo "</computer>" >> /private/tmp/EA.xml
serial=$(system_profiler SPHardwareDataType | grep 'Serial Number (system)' | awk '{print $NF}')
echo $serial
curl -sfku $apiUser:$apiPass $apiURL/JSSResource/computers/serialnumber/$serial/subset/extensionattributes -T /private/tmp/EA.xml -X PUT
sleep 5
#rm /private/tmp/EA.xml
exit 0