Last active
March 24, 2021 18:36
-
-
Save talkingmoose/f44d0d87d08b48daa0e887a6239c1766 to your computer and use it in GitHub Desktop.
Reads plain text file list of mobile device serial numbers and sends Enable Lost Mode command to each, one at a time.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# server connection information | |
URL="https://jamfpro.talkingmoose.net:8443" | |
userName="api-editor" | |
password="P@55w0rd" | |
# Lost Mode messaging | |
lostModeMsg="This iPad has been reported lost. Please help us return it." | |
lostModePhone="(612) 555-1234" | |
lostModeFootnote="The following device is being tracked with GPS coordinates" | |
# path to list of serial numbers | |
deviceList="/path/to/file.txt" | |
mobileDeviceList=$( /bin/cat "$deviceList" ) | |
# send Lost Mode command to every device in mobile device list | |
for aDevice in ${mobileDeviceList[@]} | |
do | |
# get Jamf Pro ID for device | |
deviceID=$( /usr/bin/curl -s "$URL/JSSResource/mobiledevices/serialnumber/$aDevice" \ | |
--user "$userName:$password" \ | |
--header "Accept: text/xml" \ | |
--request GET | \ | |
/usr/bin/xpath '/mobile_device/general/id/text()' ) | |
# API submission command | |
xmlData="<mobile_device_command> | |
<general> | |
<command>EnableLostMode</command> | |
<lost_mode_message>$lostModeMsg</lost_mode_message> | |
<lost_mode_phone>$lostModePhone</lost_mode_phone> | |
<lost_mode_footnote>$lostModeFootnote</lost_mode_footnote> | |
</general> | |
<mobile_devices> | |
<mobile_device> | |
<id>$deviceID</id> | |
</mobile_device> | |
</mobile_devices> | |
</mobile_device_command>" | |
# flattened XML | |
flatXML=$( /usr/bin/xmllint --noblanks - <<< "$xmlData" ) | |
/usr/bin/curl -s "$URL/JSSResource/mobiledevicecommands/command/EnableLostMode"\ | |
--user "$userName":"$password" \ | |
--header "Content-Type: text/xml" \ | |
--request POST \ | |
--data "$flatXML" | |
echo "Sending Enable Lost Mode Command to Device ID: $deviceID..." | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing.
Note that Big Sur changed the xpath version, which breaks this. Here's an updated version that includes a workaround to check OS version and parse xpath data as needed.