Category filter

Script to schedule restart on Mac

Periodic rebooting of Mac is a good practice to ensure the devices work in top conditions. It regularly clears apps’ memory, fixes peripheral and hardware issues, improves device performance, and much more. However, administrators cannot completely rely on the end-users to perform the restart action occasionally. Most users prefer to keep their devices running all the time, making them ready for action whenever they need to. In such circumstances, IT can take advantage of the custom scripts in Hexnode to schedule the periodic restart of their Macs remotely.

Scripting language – Bash

File extension – .sh

Disclaimer:

The sample scripts provided below are adapted from third-party open-source sites.

Schedule restart on macOS devices

The shutdown command is used to shut down the system. The option -r is used to specify that the system should reboot after the shutdown process is initiated.Replace hhmm with the hour and minute (in 24-hour notation) at which you need to schedule the restart of your managed devices. Once the script is executed, the devices will be rebooted at the specified time.

What happens at the device end?

Case 1: If the Terminal app is open at the device end

On executing the script, a badge notification appears on the Terminal app. On opening it, a message saying that the system is going down in ‘x’ minutes is displayed for each passing minute and finally show ‘System going down in 30 seconds’.Then the device will proceed to restart.

The countdown notification will initiate in the terminal before the device undergoes shutdown

Case 2: If the Terminal app is closed at the device end

On opening the Terminal app, ‘System going down at hh:mm’ is displayed.
When the terminal is open after script execution, it shows when the device is going to shut down

Notes:

  • The given script may fail and display the error message ‘shutdown: that time is already past’ if the specified time has already elapsed on the target devices.
  • You can also execute the Restart Device action to reboot your macOS devices remotely at your convenience.
  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository