WEBTOOLIST.
STATIC WEB PLATFORM
NO ACCOUNTS / NOTHING TO INSTALL

$ webtoolist --script failed-service-report

Failed Service Report

List systemd units that are failed or restarting, with recent log lines.

category System Administration shell Bash 4+ updated 2026-09-18
systemdserviceslogstriage
Safety notes
  • Read-only: it inspects state and logs, and changes nothing.
  • journalctl may require root or membership of the systemd-journal group.

Dependencies: systemctl, journalctl

Usage

  • Run on any systemd host.
  • Set LINES to control how many log lines are shown per failed unit.

Script

#!/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

Example

sudo ./failed-service-report
LINES=40 sudo ./failed-service-report

Notes

  • Exit status 1 means at least one unit failed — useful in monitoring wrappers.
  • Restart loops often show up as a burst of identical lines; check the unit’s restart settings next.

Related scripts

Safe Log Cleanup

Delete rotated log files older than a set number of days, with a dry-run first.

System Administration

Service Health Check

Check systemd services and HTTP endpoints in one pass with a non-zero exit on failure.

Monitoring