- Using a web browser, go to your Unifi Controller web portal
- Navigate to Control Plane > Integration
- Create a new
APIKEYand note it downAPIKEY_VALUE
Ensure you have the:
- Unifi Controller Address (
CONTROLLER_IP_ADDRESS) - APIKEY created in the previous section (
APIKEY_VALUE) - Name of the site (
SITENAME_VALUE). Usually it isDefault - Name of the managed device that you wish to reboot (
DEVICENAME_VALUE). For example,U6+,UAP-AP-M
- Ensure you have
jqinstalled to manipulate JSON contents
Content of unifi_device_reboot.sh
#!/bin/sh
# Update the corresponding values in [..] without the [] like CONTROLLER='192.168.1.1'
CONTROLLER='[CONTROLLER_IP_ADDRESS]'
APIKEY='[APIKEY_VALUE]'
SITENAME='[SITENAME_VALUE]'
DEVICENAME='[DEVICENAME_VALUE]'
### Leave the following untouched ###
# Getting the Site ID
SITEID=$(curl -s -S -k -X GET "https://${CONTROLLER}/proxy/network/integration/v1/sites" -H "X-API-KEY: ${APIKEY}" -H 'Accept: application/json' | jq -r ".data[] | select(.name == \"${SITENAME}\") | .id")
echo "Site ID: ${SITEID}"
# Getting Device ID
DEVICEID=$(curl -s -S -k -X GET "https://${CONTROLLER}/proxy/network/integration/v1/sites/${SITEID}/devices" -H "X-API-KEY: ${APIKEY}" -H 'Accept: application/json' | jq -r ".data[] | select(.name == \"${DEVICENAME}\") | .id")
echo "Device ID for \"${DEVICENAME}\": ${DEVICEID}"
# Rebooting the Device
echo "Rebooting \"${DEVICEID}\""
curl -s -S -k -X POST "https://${CONTROLLER}/proxy/network/integration/v1/sites/${SITEID}/devices/${DEVICEID}/actions" -d '{"action":"RESTART"}' -H 'Content-Type: application/json' -H "X-API-KEY: ${APIKEY}" -H 'Accept: application/json'
$ chmod +x unifi_device_reboot.sh
Schedule it using crontab