reboot_on_uptime_macos.sh - limehawk/rmm-scripts GitHub Wiki

reboot_on_uptime_macos.sh

Automatically reboots a macOS or Linux system if the uptime exceeds a specified threshold.

Overview

This script monitors system uptime and triggers an automatic reboot when the system has been running longer than a configured threshold (default: 14 days). It works on both macOS and Linux systems.

Purpose

Automatically reboots a macOS or Linux system if the uptime exceeds a specified threshold (default: 14 days).

Prerequisites

  • macOS or Linux with /proc/uptime (Linux) or uptime command (macOS)
  • Root/sudo privileges

Configuration

Required Inputs

  • max_uptime_days: Days of uptime before triggering reboot (default: 14)

Behavior

  1. Detects the operating system (macOS or Linux)
  2. Retrieves current system uptime in days
  3. Compares uptime against configured threshold
  4. If uptime exceeds threshold, triggers immediate reboot
  5. If within acceptable range, exits without action

Security Notes

  • Requires root/sudo privileges to execute reboot command
  • No sensitive information logged

Exit Codes

  • 0 = Success (reboot triggered or not needed)
  • 1 = Failure

Example Output

[ UPTIME CHECK ]
--------------------------------------------------------------
 Current Uptime      : 16 days
 Threshold           : 14 days

[ FINAL STATUS ]
--------------------------------------------------------------
 Uptime exceeds threshold. Rebooting now...

[ SCRIPT COMPLETED ]
--------------------------------------------------------------

Version History

  • v1.0.0 - Initial release

Links