Back to Resources
Level
Script
General
Ensuring that all macOS devices in an IT environment meet minimum performance standards is crucial for productivity, security, and support efficiency. Devices that fall below a defined baseline can cause performance bottlenecks, software compatibility issues, and increased help desk tickets. This script helps IT professionals and MSPs proactively monitor macOS hardware compliance and flag devices that require upgrades or replacement.
This script checks system hardware specifications—including CPU core count, total RAM, and available disk space—and compares them to the minimum standards defined in Level’s custom fields (cf_minimum_cpu, cf_minimum_ram, and cf_minimum_storage). If a device falls short in any category, it generates an alert. Additionally, the script verifies if the primary disk is an SSD and warns if an HDD is detected. When deployed as a script-based monitor in Level, it continuously enforces device compliance and provides real-time alerts when hardware fails to meet requirements.
#!/bin/bash
# This resource is provided as a convenience for Level users. We cannot
# guarantee it will work in all environments. Please test before deploying
# to your production environment. We welcome contributions to our community
# library
# Level Library
# https://level.io/library/script-macos-monitor-device-standards
# Define minimum standards
MIN_CORES={{cf_minimum_cpu}}
MIN_RAM={{cf_minimum_ram}} # in GB
MIN_DISK={{cf_minimum_storage}} # in GB
STANDARDS_BYPASS={{cf_standards_bypass}}
echo "Current STANDARDS_BYPASS value: $STANDARDS_BYPASS"
# Check for standards bypass
if [ "${STANDARDS_BYPASS}" = "true" ] || [ "${STANDARDS_BYPASS}" = "1" ]; then
echo "Standards check bypassed by configuration"
exit 0
fi
# Initialize issues array
declare -a issues
# Check CPU Cores
CPU_CORES=$(sysctl -n hw.ncpu)
if [ "$CPU_CORES" -lt "$MIN_CORES" ]; then
issues+=("ALERT: CPU has $CPU_CORES cores, below the minimum requirement of $MIN_CORES cores.")
fi
# Check RAM
TOTAL_RAM_BYTES=$(sysctl -n hw.memsize)
TOTAL_RAM_GB=$(echo "scale=2; $TOTAL_RAM_BYTES/1024/1024/1024" | bc)
if (( $(echo "$TOTAL_RAM_GB < $MIN_RAM" | bc -l) )); then
issues+=("ALERT: System has $TOTAL_RAM_GB GB of RAM, below the minimum requirement of $MIN_RAM GB.")
fi
# Check Disk Space
TOTAL_DISK_BLOCKS=$(df / | awk 'NR==2 {print $2}')
TOTAL_DISK_GB=$(echo "scale=2; $TOTAL_DISK_BLOCKS*512/1024/1024/1024" | bc)
if (( $(echo "$TOTAL_DISK_GB < $MIN_DISK" | bc -l) )); then
issues+=("ALERT: Total disk space is $TOTAL_DISK_GB GB, below the minimum requirement of $MIN_DISK GB.")
fi
# Check if disk is SSD
DISK_TYPE=$(diskutil info / | grep "Solid State" | awk '{print $3}')
if [ "$DISK_TYPE" != "Yes" ]; then
issues+=("ALERT: The primary disk is not an SSD.")
fi
# Output results
if [ ${#issues[@]} -gt 0 ]; then
printf '%s\n' "${issues[@]}"
exit 1
else
echo "System check passed:
- CPU cores: $CPU_CORES (min: $MIN_CORES)
- RAM: $TOTAL_RAM_GB GB (min: $MIN_RAM GB)
- Disk space: $TOTAL_DISK_GB GB (min: $MIN_DISK GB)"
exit 0
fi
macOS Monitor - Device Standards
This Bash script performs system requirement checks on macOS using Level Custom Fields for thresholds. It evaluates CPU cores, RAM, disk space, and SSD presence using native macOS commands like sysctl, df, and diskutil. The script stores any requirement violations in an array and outputs either the alerts with exit code 1 if checks fail, or a system specifications summary with exit code 0 if all checks pass.
Bash
100
Local system
Explore more automations, scripts, and policies to further enhance your IT operations.