Service Status Summary
Print active/inactive state for a list of systemd services.
$ webtoolist --script failed-service-report
List systemd units that are failed or restarting, with recent log lines.
systemdserviceslogstriageDependencies: systemctl, journalctl
#!/usr/bin/env bash
set -euo pipefail
lines="${LINES:-15}"
mapfile -t failed < <(systemctl --failed --no-legend --plain | awk '{print $1}')
if ((${#failed[@]} == 0)); then
echo "no failed units"
exit 0
fi
for unit in "${failed[@]}"; do
echo "== $unit =="
systemctl status "$unit" --no-pager --lines=0 | sed -n '1,6p'
journalctl -u "$unit" -n "$lines" --no-pager -o short-iso
echo
done
exit 1
sudo ./failed-service-report
LINES=40 sudo ./failed-service-report
Related scripts
Print active/inactive state for a list of systemd services.
Delete rotated log files older than a set number of days, with a dry-run first.
Summarise recent failed SSH logins by source address.
Check systemd services and HTTP endpoints in one pass with a non-zero exit on failure.