Skip to main content
Question

API Script for iPad Restart


Forum|alt.badge.img+7

Hello,

I have an iPad that is used as a permanent Time Clock in single app mode. I am hoping to find a way to make it restart automatically on a weekly basis.

Does anyone know what the JAMF API script would be to do so?

Thanks!

11 replies

Forum|alt.badge.img+18
  • Contributor
  • 475 replies
  • January 22, 2019

@dtmille2 This should work:

#!/bin/bash

# https://www.jamf.com/jamf-nation/discussions/30751/api-script-for-ipad-restart

jssURL=$(defaults read /Library/Preferences/com.jamfsoftware.jamf.plist jss_url | sed s'/.$//')

apiUser="user_here"
apiPass='password_here'
deviceID="device_ID_here"

data="<mobile_device_command><general><command>RestartDevice</command></general><mobile_devices><mobile_device><id>${deviceID}</id></mobile_device></mobile_devices></mobile_device_command>"

echo "Attempting to send a RestartDevice command to Mobile Device with ID: $deviceID"
curl -ksu "$apiUser:$apiPass" -H "Content-Type: text/xml" "$jssURL/JSSResource/mobiledevicecommands/command" -d $data -X POST

exit 0

Forum|alt.badge.img+7
  • Author
  • Contributor
  • 125 replies
  • January 22, 2019

Thank you! I will give this a go. Appreciate you taking the time.


Forum|alt.badge.img+8
  • Valued Contributor
  • 87 replies
  • August 9, 2019

Do you know how to run this against a smart or static device group? I need to restart multiple devices but other than iterating against list of device ID, not sure if this API can be ran against device groups.


Forum|alt.badge.img+7
  • Contributor
  • 82 replies
  • August 9, 2019

It does not appear that you can run it against a group. You can send to multiple device IDs at the same time though.


Forum|alt.badge.img+8
  • Valued Contributor
  • 87 replies
  • August 20, 2019

I got it working with multiple devices. If you need to run daily or weekly reboot against specific set of devices., first create an advanced mobile device search with a criteria to group the restart devices. You will need to find the advanced mobile device search ID, you can find the advanced mobile device search ID by clicking the advanced mobile device search you just created and the URL should show up like this.

https://jss.domain.com:8443/advancedMobileDeviceSearches.html?id=1&o=r

ID will be in the URL. Use this for amds_id variable. Other variables should be easy to find. The first curl command with bunch of sed command is not pretty but it works for me for now. If you can think of better way of doing it, let me know.

#!/bin/sh
# Define Variables

### JAMF Pro username / password
apiUser="user_name"
apiPass='password'

### JAMF Pro URL
jssurl="jss.domain.com:8443"

### advanced mobile device search ID number
amds_id=""

# 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" 
| xpath /advanced_mobile_device_search/mobile_devices/mobile_device/id | sed 's/<id>//g' | sed 's/</id>/,/g' | rev | sed 's/,//' | rev`

# Send restart command against the mobile device IDs retreive in the previous command. 
curl -ksu "$apiUser:$apiPass" -X POST "https://$jssurl/JSSResource/mobiledevicecommands/command/RestartDevice/id/$mobile_devices" -H "accept: application/xml"

exit

Forum|alt.badge.img+3
  • New Contributor
  • 2 replies
  • January 31, 2020

New to jamf. I've seen a few threads like this about scheduling iPad restarts and that's exactly what I want to do.

What does the script above need to run on? Is there jamf server software I need to have in order to make scheduled iPad restarts work? I currently only have a jamf NOW account and have my iPad successfully enrolled in it.

Thanks for any pointers you can offer! :-)
Matt


Forum|alt.badge.img
  • New Contributor
  • 1 reply
  • February 25, 2022
tak10 wrote:

I got it working with multiple devices. If you need to run daily or weekly reboot against specific set of devices., first create an advanced mobile device search with a criteria to group the restart devices. You will need to find the advanced mobile device search ID, you can find the advanced mobile device search ID by clicking the advanced mobile device search you just created and the URL should show up like this.

https://jss.domain.com:8443/advancedMobileDeviceSearches.html?id=1&o=r

ID will be in the URL. Use this for amds_id variable. Other variables should be easy to find. The first curl command with bunch of sed command is not pretty but it works for me for now. If you can think of better way of doing it, let me know.

#!/bin/sh
# Define Variables

### JAMF Pro username / password
apiUser="user_name"
apiPass='password'

### JAMF Pro URL
jssurl="jss.domain.com:8443"

### advanced mobile device search ID number
amds_id=""

# 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" 
| xpath /advanced_mobile_device_search/mobile_devices/mobile_device/id | sed 's/<id>//g' | sed 's/</id>/,/g' | rev | sed 's/,//' | rev`

# Send restart command against the mobile device IDs retreive in the previous command. 
curl -ksu "$apiUser:$apiPass" -X POST "https://$jssurl/JSSResource/mobiledevicecommands/command/RestartDevice/id/$mobile_devices" -H "accept: application/xml"

exit

Okay, so I am fairly new to this, I am looking at your code, where in there do I set the schedule for the devices to restart, can I set it to restart from say 12:00AM to 01:00AM? I don't want them to run into an issue and I would rather them all restart on their own between this time. I also cannot find where I put this code in. I went to the API URL but i don't see where I can enter the code into.


chrisdaggett
Forum|alt.badge.img+7
  • Valued Contributor
  • 94 replies
  • November 2, 2022
mattriley wrote:

New to jamf. I've seen a few threads like this about scheduling iPad restarts and that's exactly what I want to do.

What does the script above need to run on? Is there jamf server software I need to have in order to make scheduled iPad restarts work? I currently only have a jamf NOW account and have my iPad successfully enrolled in it.

Thanks for any pointers you can offer! :-)
Matt


You need to setup a cron job (launchd) to run the script on schedule on any macOS device thats always on. 


chrisdaggett
Forum|alt.badge.img+7
  • Valued Contributor
  • 94 replies
  • November 2, 2022
Bkilleen wrote:

Okay, so I am fairly new to this, I am looking at your code, where in there do I set the schedule for the devices to restart, can I set it to restart from say 12:00AM to 01:00AM? I don't want them to run into an issue and I would rather them all restart on their own between this time. I also cannot find where I put this code in. I went to the API URL but i don't see where I can enter the code into.


You have to run the script as part of a cron job (launchd) on a mac. That is how you specify when and how often to run it. This is just the script itself. There is no way to accomplish this by jamf, unfortunately. 


Forum|alt.badge.img+3
  • New Contributor
  • 4 replies
  • October 13, 2023
tak10 wrote:

I got it working with multiple devices. If you need to run daily or weekly reboot against specific set of devices., first create an advanced mobile device search with a criteria to group the restart devices. You will need to find the advanced mobile device search ID, you can find the advanced mobile device search ID by clicking the advanced mobile device search you just created and the URL should show up like this.

https://jss.domain.com:8443/advancedMobileDeviceSearches.html?id=1&o=r

ID will be in the URL. Use this for amds_id variable. Other variables should be easy to find. The first curl command with bunch of sed command is not pretty but it works for me for now. If you can think of better way of doing it, let me know.

#!/bin/sh
# Define Variables

### JAMF Pro username / password
apiUser="user_name"
apiPass='password'

### JAMF Pro URL
jssurl="jss.domain.com:8443"

### advanced mobile device search ID number
amds_id=""

# 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" 
| xpath /advanced_mobile_device_search/mobile_devices/mobile_device/id | sed 's/<id>//g' | sed 's/</id>/,/g' | rev | sed 's/,//' | rev`

# Send restart command against the mobile device IDs retreive in the previous command. 
curl -ksu "$apiUser:$apiPass" -X POST "https://$jssurl/JSSResource/mobiledevicecommands/command/RestartDevice/id/$mobile_devices" -H "accept: application/xml"

exit

Trying to use this, it seems the line 

mobile_devices=`curl <code> | rev`

is giving a syntax error, any idea?


Forum|alt.badge.img+4
  • New Contributor
  • 7 replies
  • December 8, 2023
maxwolf wrote:

Trying to use this, it seems the line 

mobile_devices=`curl <code> | rev`

is giving a syntax error, any idea?


I am getting a similar error. were you able to get this working?


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