Posted on 01-22-2019 05:29 AM
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!
Posted on 01-22-2019 06:21 AM
@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
Posted on 01-22-2019 08:07 AM
Thank you! I will give this a go. Appreciate you taking the time.
Posted on 08-09-2019 12:51 PM
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.
Posted on 08-09-2019 04:33 PM
It does not appear that you can run it against a group. You can send to multiple device IDs at the same time though.
Posted on 08-20-2019 02:36 PM
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
Posted on 02-25-2022 01:16 PM
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.
Posted on 11-02-2022 09:36 AM
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.
Posted on 10-13-2023 03:58 PM
Trying to use this, it seems the line
mobile_devices=`curl <code> | rev`
is giving a syntax error, any idea?
Posted on 12-08-2023 10:07 AM
I am getting a similar error. were you able to get this working?
Posted on 01-31-2020 01:10 PM
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
Posted on 11-02-2022 09:34 AM
You need to setup a cron job (launchd) to run the script on schedule on any macOS device thats always on.