Skip to main content
Question

Send mobile device command to mobile device smart group


Forum|alt.badge.img+3

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!

3 replies

Forum|alt.badge.img+3
  • New Contributor
  • 8 replies
  • May 9, 2019

I'll bump this since I actually have the same question.


Forum|alt.badge.img+20
  • Employee
  • 77 replies
  • May 9, 2019

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>

Forum|alt.badge.img+1
  • New Contributor
  • 1 reply
  • April 14, 2020

@jose.gutierrez @evan684

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

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings