Jamf pro 300 ( Day 2 ) Section 2 : Automation
Lession 8 API part1 (resd data)
Lession 9 API part2 (update create delete)
Lession 10 Scripting part1 (compose scripts with variables and prompt)
Lession 11 Scripting part2 (compose scripts with loop)
https://pro.jamf.training:8443/08/api/
https://pro.jamf.training:8443/08/JSSResources ?
Lession 8 API part1 (read data)
Task 1 print site list to a file
https://docs.jamf.com/education-services/resources/20181220/300_S2_L8.html
API
Get all computers
curl -sku USERNAME:PASSWORD -H “accept: text/xml” https://pro.jamf.training:8443/##/JSSResource/computers
Get all sites and output to a file
curl -sku USERNAME:PASSWORD -H “accept: text/xml” https://pro.jamf.training:8443/##/JSSResource/sites -o /PATH/TO/FILE
Get a mobile device and pretty-print the output
curl -sku USERNAME:PASSWORD -H “accept: text/xml” https://pro.jamf.training:8443/##/JSSResource/mobiledevices/id/3000 | xmllint –format –
Get a mobile device and find the building
curl -sku USERNAME:PASSWORD -H “accept: text/xml” https://pro.jamf.training:8443/##/JSSResource/mobiledevices/id/3000 | xmllint –xpath ‘/mobile_device/location/building/text()’ –
Find the buildling of a mobile device
curl -sku USERNAME:PASSWORD -H “accept: text/xml” https://pro.jamf.training:8443/##/JSSResource/mobiledevices/id/3000 | xmllint –xpath ‘//building/text()’-
Get all categories
curl -sku USERNAME:PASSWORD -H “accept: text/xml” https://pro.jamf.training:8443/##/JSSResource/categories
!/bin/bash
apiUser=”jamfadmin”
apiPass=”jamf1234″
sID=”08″
#curl -sku $apiUser:$apiPass -H “accept: text/xml” https://pro.jamf.training:8443/$sID/JSSResource/sites | xmllint –xpath ‘/sites/site/name/text()’ -o /Users/localadmin/Desktop/output/ListofSites.txt
curl -sku $apiUser:$apiPass -H “accept: text/xml” https://pro.jamf.training:8443/$sID/JSSResource/sites -o /Users/localadmin/Desktop/output/ListofSites.txt
curl -sku $apiUser:$apiPass -H “accept: text/xml” https://pro.jamf.training:8443/$sID/JSSResource/mobiledevices/id/100 | xmllint –xpath ‘/mobile_device/location/building/text()’ –
Task 2 format the response of the managed clients smart group
#!/bin/bash
apiUser=”jamfadmin”
apiPass=”jamf1234″
sID=”08″
curl -sku $apiUser:$apiPass -H “accept: text/xml” https://pro.jamf.training:8443/$sID/JSSResource/mobiledevicegroups | xmllint –format –
? Task 3 format the inventory record to your computer; printer to file
#!/bin/bash
apiUser=”jamfadmin”
apiPass=”jamf1234″
sID=”08″
mySerial=`system_profiler SPHardwareDataType | awk ‘/Serial Number/{print $4}’`
curl -sku $apiUser:$apiPass -H “accept: text/xml” https://pro.jamf.training:8443/$sID/JSSResource/computers/serialnumber/$mySerial | xmllint –format –
Task 4 print a activation code without xml tag
#!/bin/bash
apiUser=”jamfadmin”
apiPass=”jamf1234″
sID=”08″
curl -sku $apiUser:$apiPass -H “accept: text/xml” https://pro.jamf.training:8443/$sID/JSSResource/activationcode | xmllint –xpath ‘/activation_code/code/text()’ –
Lession 9 API part2 (update create delete)
Task 1 Create the update catagory
#!/bin/bash
apiUser=”jamfadmin”
apiPass=”jamf1234″
sID=”08″
curl -sku $apiUser:$apiPass -H “content-type: text/xml” https://pro.jamf.training:8443/$sID/JSSResource/categories/id/0 -X POST -d “<category><name>NoNameUnknown</name></category>”
Task 2 move your computer to Testing site
#!/bin/bash
apiUser=”jamfadmin”
apiPass=”jamf1234″
sID=”08″
mySerial=`system_profiler SPHardwareDataType | awk ‘/Serial Number/{print $4}’`
curl -sku $apiUser:$apiPass -H “content-type: text/xml” https://pro.jamf.training:8443/$sID/JSSResource/computers/serialnumber/$mySerial -X PUT -d “<computer><general><site><name>Testing</name></site></general></computer>”
#curl -sku $apiUser:$apiPass -H “content-type: text/xml” https://pro.jamf.training:8443/$sID/JSSResource/computers/id/100 -X PUT -d “<computer><general><site><name>Testing</name></site></general></computer>”
Task 3 move your mobile device to production site
#!/bin/bash
apiUser=”jamfadmin”
apiPass=”jamf1234″
sID=”08″
#mySerial=`system_profiler SPHardwareDataType | awk ‘/Serial Number/{print $4}’`
#curl -sku $apiUser:$apiPass -H “content-type: text/xml” https://pro.jamf.training:8443/$sID/JSSResource/computers/serialnumber/$mySerial -X PUT -d “<computer><general><site><name>Production</name></site></general></computer>”
curl -sku $apiUser:$apiPass -H “content-type: text/xml” https://pro.jamf.training:8443/$sID/JSSResource/mobiledevices/id/100 -X PUT -d “<mobile_device><general><site><name>Testing</name></site></general></mobile_device>”
Task 4 send an update inventory command to your mobile device
#!/bin/bash
apiUser=”jamfadmin”
apiPass=”jamf1234″
sID=”08″
curl -sku $apiUser:$apiPass -H “content-type: text/xml” https://pro.jamf.training:8443/$sID/JSSResource/mobiledevicecommands/command/UpdateInventory/id/100 -X POST
Lession 10 Scripting part1 (compose scripts with variables and prompt)
Task 1 compose a script let myID myassignuser mysitename to variable
#!/bin/bash
apiUser=”jamfadmin”
apiPass=”jamf1234″
sID=”08″
mySerial=`system_profiler SPHardwareDataType | awk ‘/Serial Number/{print $4}’`
#echo “$mySerial”
myid=`curl -sku $apiUser:$apiPass -H “accept: text/xml” https://pro.jamf.training:8443/$sID/JSSResource/computers/serialnumber/$mySerial | xmllint –xpath ‘/computer/general/id/text()’ -`
echo “$myid”
myassignuser=`curl -sku $apiUser:$apiPass -H “accept: text/xml” https://pro.jamf.training:8443/$sID/JSSResource/computers/serialnumber/$mySerial | xmllint –xpath ‘/computer/location/username/text()’ -`
echo “$myassignuser”
mysitename=`curl -sku $apiUser:$apiPass -H “accept: text/xml” https://pro.jamf.training:8443/$sID/JSSResource/computers/serialnumber/$mySerial | xmllint –xpath ‘/computer/general/site/name/text()’ -`
echo “$mysitename”
Task 2 compose a script
#!/bin/bash
apiUser=”jamfadmin”
apiPass=”jamf1234″
sID=”08″
mySerial=`system_profiler SPHardwareDataType | awk ‘/Serial Number/{print $4}’`
assetTag=$(osascript -e ‘text returned of (display dialog “Please Give me your Asset Tag (HINT: on the bottom of your computer)” default answer “AB13456789” buttons {“Cancel”,”OK”} default button 2)’)
echo “Asset Tag is $assetTag”
curl -sku $apiUser:$apiPass -H “content-type: text/xml” https://pro.jamf.training:8443/$sID/JSSResource/computers/serialnumber/$mySerial -X PUT -d “<computer><general><asset_tag>$assetTag</asset_tag></general></computer>”
prompt a user for a serial number of mobile device
print username assign to the mobile device
#!/bin/bash
apiUser=”jamfadmin”
apiPass=”jamf1234″
sID=”08″
#mySerial=`system_profiler SPHardwareDataType | awk ‘/Serial Number/{print $4}’`
# DLXS8AQ9HGJ1
sn168=$(osascript -e ‘text returned of (display dialog “Please Give me your Mobile Device SN (HINT: Like DLXS8AQ9HGJ1)” default answer “DLXS8AQ9HGJ1-168” buttons {“Cancel”,”OK”} default button 2)’)
echo “Mobile Device SN is $sn168”
curl -sku $apiUser:$apiPass -H “content-type: text/xml” https://pro.jamf.training:8443/$sID/JSSResource/mobiledevices/serialnumber/$sn168 | xmllint –xpath ‘/mobile_device/location/username/text()’ –
Task 3
Prompt user for the policy ID
Execute the policy
print the policy output to /Users/Shared
Task 4 GuestEnable Extension Attribute
Lession 11 Scripting part2 (compose scripts with loop)
Task 1 Compose a script with for-loop to create department (Art Music Math Science History)
#!/bin/bash
apiUser=”jamfadmin”
apiPass=”jamf1234″
sID=”08″
department=”Art Music Math Sicense History”
for i in ${department}
do
echo “Create Department $i”
curl -sku $apiUser:$apiPass -H “content-type: text/xml” https://pro.jamf.training:8443/$sID/JSSResource/departments/id/0 -X POST -d “<department><name>$i</name></department>”
done
Task 2 Compose a script to do the following
check whether a file (parameter 4) exist
if exist ,show a message (parameter 5)
#!/bin/bash
# Exit if $4 is empty
if [[ -z $4 ]]||[[ -z $5 ]];then
echo “Parameter 4 or 5 is empty. Exiting”
exit 1
else
pathToCheck=${4}
MessageToDisplay=${5}
fi
echo “Parameter 4 is $pathToCheck”
if [[ -f $pathToCheck ]];then
echo “File Exists.”
jamf displayMessage -message “${MessageToDisplay}”
else
echo “File Missing.”
fi
Task 3 Create a policy to execute script (Task 2 script)
(parameter 4) /users/Shared/managementTime.txt
(parameter 5) “Your management framework was update recently”
Maintainencen(update inventory)
P29 Grow Review
Compose a script to do the following
loop through the file (/users/Shared/Resources/deviceAssignment.csv.txt)
assign variable to the fields
using the serial number to update the room number and asset tag for the specified mobile devices
#!/bin/bash
inputFile=”/Users/Shared/Resources/Docs/deviceAssignment.csv”
while IFS=, read -r id AssetTag Serial; do
echo “Device $Serial has an ID of $id has an AssetTag of $AssetTag.”
# Example of CSV updating Jamf PRO Computer Record
# if [[ $mySerial==$Serial ]];then
# curl -sku https:///projamf…/JSSResources/computers -H “content-type” -X PUT Assettag
# fi
done < “${inputFile}”
EXAM 01
Create a standard user with run api and view the computer information priviledge.
Create a Extension Attribute to check the last restart time
#!/bin/bash
bootTime=$(sysctl kern.boottime | awk ‘{print $5}’ | tr -d ,)
echo “$bootTime”
bootTimeFormatted=$(date -jf %s $bootTime +%F\ %T)
echo “<result>$bootTimeFormatted</result>”
Create a Smart computer group that last restart time more than 45 days
Create a computer configuration profile to run the script ( upload system log and remind user to restart computer ASAP ) including the last restart time more than 45 days
近期留言