-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitor.sh
More file actions
31 lines (27 loc) · 831 Bytes
/
monitor.sh
File metadata and controls
31 lines (27 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env bash
# monitor.sh — Quick system health overview with logging.
set -Eeuo pipefail
LOG_DIR="${LOG_DIR:-/var/log/sysadmin-tools}"
mkdir -p "${LOG_DIR}"
LOG_FILE="${LOG_DIR}/monitor.log"
ts() { date -Is; }
{
echo "==== [monitor] $(ts)"
echo "[uptime]" && uptime
echo
echo "[memory]" && free -h
echo
echo "[disk]" && df -h | awk 'NR==1 || /^\/(dev|mnt|srv)/ {print}'
echo
if command -v smartctl >/dev/null 2>&1; then
echo "[smartctl] short summary (first 2 disks if present)"
for d in /dev/sd[a-z] /dev/nvme[0-9]n1 2>/dev/null; do
[[ -e "$d" ]] || continue
smartctl -H "$d" | sed 's/^/ /'
done | head -n 40
echo
fi
} | tee -a "${LOG_FILE}"
echo "==== [monitor] done"
# Example cron entry to run every hour:
# 0 * * * * /path/to/monitor.sh >> /var/log/monitor.log 2>&1