ipad API restart script not working

New Contributor

We have a script that takes a group of IOS devices and restart all devices in it. The part of the script that gets the iOS devices works but the restart part doesnt work.Any suggestions?
The script looks something like this:

# Define Variables

### JAMF Pro username / password

### JAMF Pro URL

### advanced mobile device search ID number

# Get Mobile Device IDs from advanced mobile device search. This will retreive all device IDs from advanced mobile device search id 1. Change the id # to retreive from different advanced mobile device search.
mobile_devices=`curl -ksu "$apiUser:$apiPass" -X GET "https://$jssurl/JSSResource/advancedmobiledevicesearches/id/$amds_id" -H "accept: application/xml" | xmllint --xpath "//mobile_devices/mobile_device/id" - | sed 's/</id>/
/g' | sed 's/<id>//g'`

for mobile_device in $mobile_devices
  echo "Attempting to send a RestartDevice command to Mobile Device with ID: $mobile_device"
curl -ksu "$apiUser:$apiPass" -X POST "https://$jssurl:8443/JSSResource/mobiledevicecommands/command/RestartDevice/id/$mobile_device" -H "accept: application/xml"



New Contributor III
New Contributor III

@rotorstudios embrace awk

mobile_devices=$(curl -ksu "$apiUser:$apiPass" -X GET "$jssurl/JSSResource/advancedmobiledevicesearches/id/$amds_id" -H "accept: application/xml" | xpath //mobile_devices/mobile_device/id | awk -F'<id>|</id>' '{print $2}')

Hope that helps

when in doubt echo out your $mobile_devices to see what you're getting

I also made a change where the url variable includes your https://<serverurl>:8443 makes it easer to change in the long run

New Contributor

Sorry, the issue is in the RestartDevices command. The part to get mobile_devices work fine in the original script.
Also, it seems that the part to get mobile_devices doesnt need port 8443 but if we do not include port 8443 in the RestartDevice url, it fails with an authentication error.

New Contributor III
New Contributor III

Sorry I mis understood,

I recommend having a look at the code example on developer.jamf.com
might give you an idea on combining them both


Daniel MacLaughlin

New Contributor

ok. looks like my script was fine but the user's permission for whatever reason, in the jamf pro server objects under the create colum, the mobile device checkbox needs to be ticked. not sure why or if this is going to be a problem but without this, the script fails/hangs

Contributor III

I work in K-12 and an app vendor suggested we reboot the devices weekly to resolve some issue the app was having. Awesome. I wrote this script that I run with a launchAgent to execute it weekly to reboot some Mobile Device Smart Groups in the jamfPro server. It has a nested for loops that grabs the device ids out of a group and reboots them all, then continues to the next group.
You can grab the ID of the smart group by looking for it in the URL when viewing the Smart Group.

Like this:


So the Group ID in this example would be 711

# written by Steven Russell
# supply the id of the smart groups in the group_id_array variable 
# to have them reboot all the mobile devices in the smart group


## Fill in the Smart Group ID(s) here:
group_id_array=(471 472 2617)
for group_id in "${group_id_array[@]}"; do
    ## Grab the members of the group:
    members_of_group=$(curl -su "${jssuser}":"${jsspass}" "${jssurl}"/JSSResource/mobiledevicegroups/id/${group_id} | xpath //mobile_devices/mobile_device/id | tr '</id>' '
    array_id=$(echo $members_of_group | awk '$1=$1' | tr '
' ' ')
    sleep 1 ## slow things down a bit cowboy

    ## Loop through the users and perform the reboot:
    for mobile_id in $array_id; do
        curl -su "${jssuser}":"${jsspass}" "${jssurl}"/JSSResource/mobiledevicecommands/command/RestartDevice/id/"${mobile_id}" -X POST
        sleep 1

exit 0