80 lines
1.6 KiB
Bash
Executable File
80 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
host="$(hostname)"
|
|
timestamp="$(date '+%Y-%m-%d_%H%M%S')"
|
|
report="/tmp/system_report_${host}_${timestamp}.txt"
|
|
|
|
section() {
|
|
printf '\n== %s ==\n' "$1"
|
|
}
|
|
|
|
run_or_warn() {
|
|
local description="$1"
|
|
shift
|
|
|
|
if command -v "$1" >/dev/null 2>&1; then
|
|
"$@" || printf 'WARNING: %s command failed\n' "$description"
|
|
else
|
|
printf 'WARNING: %s command not available\n' "$1"
|
|
fi
|
|
}
|
|
|
|
{
|
|
section "Host"
|
|
hostname
|
|
|
|
section "Date"
|
|
date
|
|
|
|
section "Uptime"
|
|
uptime
|
|
|
|
section "OS"
|
|
if [[ -r /etc/os-release ]]; then
|
|
. /etc/os-release
|
|
printf '%s\n' "${PRETTY_NAME:-Unknown Linux}"
|
|
else
|
|
printf 'WARNING: /etc/os-release not readable\n'
|
|
fi
|
|
|
|
section "Kernel"
|
|
uname -r
|
|
|
|
section "CPU Load"
|
|
if [[ -r /proc/loadavg ]]; then
|
|
awk '{print "1m="$1, "5m="$2, "15m="$3}' /proc/loadavg
|
|
else
|
|
uptime
|
|
fi
|
|
|
|
section "Memory"
|
|
run_or_warn "memory usage" free -h
|
|
|
|
section "Disk"
|
|
run_or_warn "disk usage" df -h -x tmpfs -x devtmpfs
|
|
|
|
section "Failed systemd Services"
|
|
if command -v systemctl >/dev/null 2>&1; then
|
|
systemctl --failed --no-pager || true
|
|
else
|
|
printf 'WARNING: systemctl command not available\n'
|
|
fi
|
|
|
|
section "Listening Ports"
|
|
if command -v ss >/dev/null 2>&1; then
|
|
ss -tuln || printf 'WARNING: ss command failed\n'
|
|
else
|
|
printf 'WARNING: ss command not available\n'
|
|
fi
|
|
|
|
section "Recent Kernel Messages"
|
|
if command -v journalctl >/dev/null 2>&1; then
|
|
journalctl -k -n 50 --no-pager || printf 'WARNING: journalctl kernel log query failed\n'
|
|
else
|
|
printf 'WARNING: journalctl command not available\n'
|
|
fi
|
|
} > "$report"
|
|
|
|
printf 'System report written to: %s\n' "$report"
|