Posted on 03-20-2019 06:04 PM
Hello!
I need to send the update inventory command to my iPads to be able to check when they run out of battery.
Gladly i succeeded writing the test script to send it to one device, but i im looking for a way to send it to a whole group instead of doing it device per device.
This is the beautiful script.
#!/bin/bash
deviceID="59"
# This works for single commands
data="<mobile_device_command><general><command>UpdateInventory</command></general><mobile_devices><mobile_device><id>59</id></mobile_device></mobile_devices></mobile_device_command>"
curl -fsku "${usr}:${pass}" -H "Content-Type: text/xml" "${jssdomain}/JSSResource/mobiledevicecommands/command" -d $data -X POST
Do you have any idea of how would it work for mobile devices smart groups?
Regards!
Posted on 05-09-2019 10:42 AM
I'll bump this since I actually have the same question.
Posted on 05-09-2019 10:48 AM
To send this to multiple devices, you would just add additional instances of the mobile device ID to the existing XML array. For example:
<mobile_device_command>
<general>
<command>UpdateInventory</command>
</general>
<mobile_devices>
<mobile_device>
<id>59</id>
</mobile_device>
<mobile_device>
<id>60</id>
</mobile_device>
</mobile_devices>
</mobile_device_command>
Posted on 04-14-2020 12:48 PM
Had the same problem and thought this might help you guys out
#!/bin/sh
jamfProURL="https://jamf.jamfcloud.com"
jamfUser="jamf.admin"
jamfPass="jamf1234"
mobileDeviceGroupID="69"
mobileDeviceCommand="SettingsEnableDataRoaming"
##############################
# Mobile Device Commands: #
# UpdateInventory #
# BlankPush #
# SettingsEnableDataRoaming #
# Full list: #
# https://developer.jamf.com #
##############################
deviceIDs=( $( curl -s -u "$jamfUser":"$jamfPass" $jamfProURL/JSSResource/mobiledevicegroups/id/$mobileDeviceGroupID -H "Accept: application/xml" -X GET | xpath "//mobile_device_group/mobile_devices" | /usr/bin/perl -lne 'BEGIN{undef $/} while (/<id>(.*?)</id>/sg){print $1}' ) )
for i in ${deviceIDs[@]}; do
echo "Sending $mobileDeviceCommand to Device ID: $i..."
/usr/bin/curl -sk -u "$jamfUser":"$jamfPass" -H "Content-Type: text/xml" -d "<?xml version="1.0" encoding="ISO-8859-1"?><mobile_device_command><general><command>$mobileDeviceCommand</command>></general><mobile_devices><mobile_device><id>$i</id></mobile_device></mobile_devices></mobile_device_command>" $jamfProURL/JSSResource/mobiledevicecommands/command/$mobileDeviceCommand -X POST > /dev/null
if [[ "$?" == "0" ]]; then
echo " $mobileDeviceCommand Command Processed Successfully"
else
echo " $mobileDeviceCommand Error Processing Command"
fi
echo ""
done
exit 0