Project: Health Check
Is everything OK?.
Admins like a quick answer to one question. Is this computer OK? Let's build a health check script that shows disk, memory, and processes, and warns us when the disk is getting full.

- Is this computer OK?
- Disk, memory, processes
- Warn when the disk is full
health.sh
Dollar, brace, one, colon dash ninety means, use the first argument, or ninety if there isn't one. DF with dash dash output gives just the percentage used, and TR strips everything but the digits. Awk picks the available memory, and PS counts the processes. Finally, if compares the disk with the limit.
#!/bin/bash
limit="${1:-90}"
disk=$(df --output=pcent / | tail -n 1 | tr -dc 0-9)
echo "== Health check: $(hostname), $(date +%F) =="
echo "Disk used: $disk%"
echo "Memory free: $(free -h | awk '/Mem/ {print $7}')"
echo "Processes: $(ps -e --no-headers | wc -l)"
if [ "$disk" -gt "$limit" ]; then
echo "WARNING: disk is over $limit%!"
else
echo "Disk OK (limit $limit%)"
fiChecking the health
With the normal limit, everything's fine. Disk OK. Now we pass a tiny limit, ten percent, to test the warning. This time the script warns us. Always test the unhappy path too.
./health.sh == Health check: laptop, 2026-01-05 == Disk used: 41% Memory free: 8.6Gi Processes: 5 Disk OK (limit 90%) ./health.sh 10 == Health check: laptop, 2026-01-05 == Disk used: 41% Memory free: 8.6Gi Processes: 5 WARNING: disk is over 10%!
Where to take it
Put the health check in cron, every hour, and save its output to a log. Or only send a message when there's a warning. The same idea scales up to the monitoring tools big companies use. They're just much fancier health checks.
| key | value |
|---|---|
| ${1:-90} | argument, or a default |
| df --output=pcent | just the percentage |
| tr -dc 0-9 | keep only digits |
| cron hourly | check all the time |
Summary
The health check reports disk, memory, and processes, and warns when the disk passes a limit. Next, a backup script that tidies up after itself.
Key takeaways- ${1:-default}
- df, free, ps
- if [ "$disk" -gt "$limit" ]