4.1 System State (+ Default Target & Status)
4.2 Failed Units
4.3 Failed Unit Details (Status & Logs loop)
4.4 Running Services
4.5 Enabled Services
4.6 Disabled Services
4.7 Masked Units
4.8 Systemd Jobs
4.9 Boot Critical Chain
4.10 Long-running Startup Units (Blame)
4.11 Systemd Timers
4.12 Recent System Errors (Journalctl -p err)
4.13 Recent Service Restart Activity
Copy–>Past
echo "==================== 04. SERVICES & SYSTEMD ===================="; printf "\n"; echo "4.1 SYSTEM STATE"; echo "--- Overall State ---"; systemctl is-system-running 2>/dev/null || echo "System state check unavailable"; printf "\n"; echo "--- Default Target ---"; systemctl get-default 2>/dev/null || echo "Default target unavailable"; printf "\n"; echo "--- System Status ---"; systemctl status --no-pager 2>/dev/null | head -50 || echo "Global systemd status unavailable"; printf "\n%.0s" {1..3}; echo "4.2 FAILED UNITS"; systemctl --failed --all --no-pager 2>/dev/null || echo "Failed unit tracking unavailable"; printf "\n%.0s" {1..3}; echo "4.3 FAILED UNIT DETAILS"; FAILED_UNITS=$(systemctl --failed --type=service --no-legend --plain 2>/dev/null | awk '{print $1}'); if [ -n "$FAILED_UNITS" ]; then for UNIT in $FAILED_UNITS; do echo "--- $UNIT ---"; systemctl status "$UNIT" --no-pager --full 2>/dev/null | head -40; printf "\n"; journalctl -u "$UNIT" -b -n 30 --no-pager 2>/dev/null; printf "\n"; done; else echo "No failed service units"; fi; printf "\n%.0s" {1..3}; echo "4.4 RUNNING SERVICES"; systemctl list-units --type=service --state=running --no-pager --no-legend 2>/dev/null | head -80 || echo "Running services listing unavailable"; printf "\n%.0s" {1..3}; echo "4.5 ENABLED SERVICES"; systemctl list-unit-files --type=service --state=enabled --no-pager --no-legend 2>/dev/null | head -80 || echo "Enabled service listing unavailable"; printf "\n%.0s" {1..3}; echo "4.6 DISABLED SERVICES"; systemctl list-unit-files --type=service --state=disabled --no-pager --no-legend 2>/dev/null | head -80 || echo "Disabled service listing unavailable"; printf "\n%.0s" {1..3}; echo "4.7 MASKED UNITS"; systemctl list-unit-files --state=masked --no-pager 2>/dev/null || echo "Masked unit listing unavailable"; printf "\n%.0s" {1..3}; echo "4.8 SYSTEMD JOBS"; systemctl list-jobs --no-pager 2>/dev/null || echo "No pending systemd jobs or listing unavailable"; printf "\n%.0s" {1..3}; echo "4.9 BOOT CRITICAL CHAIN"; if command -v systemd-analyze >/dev/null 2>&1; then systemd-analyze critical-chain --no-pager 2>/dev/null | head -50; else echo "systemd-analyze not installed"; fi; printf "\n%.0s" {1..3}; echo "4.10 LONG-RUNNING STARTUP UNITS"; if command -v systemd-analyze >/dev/null 2>&1; then systemd-analyze blame 2>/dev/null | head -30; else echo "systemd-analyze not installed"; fi; printf "\n%.0s" {1..3}; echo "4.11 SYSTEMD TIMERS"; systemctl list-timers --all --no-pager 2>/dev/null || echo "Systemd timer listing unavailable"; printf "\n%.0s" {1..3}; echo "4.12 RECENT SYSTEM ERRORS"; if command -v journalctl >/dev/null 2>&1; then journalctl -p err -b --no-pager 2>/dev/null | tail -n 50; else echo "journalctl not available"; fi; printf "\n%.0s" {1..3}; echo "4.13 RECENT SERVICE RESTART ACTIVITY"; if command -v journalctl >/dev/null 2>&1; then journalctl -b --no-pager 2>/dev/null | grep -Ei 'Started |Stopped |Starting |Stopping |Failed to start|Main process exited|Scheduled restart job' | tail -n 80 || echo "No recent service restart activity found"; else echo "journalctl not available"; fi
# ==================== 04. SERVICES & SYSTEMD ====================
echo "==================== 04. SERVICES & SYSTEMD ===================="
printf "\n"
# --- 4.1 SYSTEM STATE ---
echo "4.1 SYSTEM STATE"
echo "--- Overall State ---"
systemctl is-system-running 2>/dev/null || echo "System state check unavailable"
printf "\n"
echo "--- Default Target ---"
systemctl get-default 2>/dev/null || echo "Default target unavailable"
printf "\n"
echo "--- System Status ---"
systemctl status --no-pager 2>/dev/null | head -50 || echo "Global systemd status unavailable"
printf "\n%.0s" {1..3}
# --- 4.2 FAILED UNITS ---
echo "4.2 FAILED UNITS"
systemctl --failed --all --no-pager 2>/dev/null || echo "Failed unit tracking unavailable"
printf "\n%.0s" {1..3}
# --- 4.3 FAILED UNIT DETAILS ---
echo "4.3 FAILED UNIT DETAILS"
FAILED_UNITS=$(systemctl --failed --type=service --no-legend --plain 2>/dev/null | awk '{print $1}')
if [ -n "$FAILED_UNITS" ]; then
for UNIT in $FAILED_UNITS; do
echo "--- $UNIT ---"
systemctl status "$UNIT" --no-pager --full 2>/dev/null | head -40
printf "\n"
journalctl -u "$UNIT" -b -n 30 --no-pager 2>/dev/null
printf "\n"
done
else
echo "No failed service units"
fi
printf "\n%.0s" {1..3}
# --- 4.4 RUNNING SERVICES ---
echo "4.4 RUNNING SERVICES"
systemctl list-units --type=service --state=running --no-pager --no-legend 2>/dev/null | head -80 || \
echo "Running services listing unavailable"
printf "\n%.0s" {1..3}
# --- 4.5 ENABLED SERVICES ---
echo "4.5 ENABLED SERVICES"
systemctl list-unit-files --type=service --state=enabled --no-pager --no-legend 2>/dev/null | head -80 || \
echo "Enabled service listing unavailable"
printf "\n%.0s" {1..3}
# --- 4.6 DISABLED SERVICES ---
echo "4.6 DISABLED SERVICES"
systemctl list-unit-files --type=service --state=disabled --no-pager --no-legend 2>/dev/null | head -80 || \
echo "Disabled service listing unavailable"
printf "\n%.0s" {1..3}
# --- 4.7 MASKED UNITS ---
echo "4.7 MASKED UNITS"
systemctl list-unit-files --state=masked --no-pager 2>/dev/null || \
echo "Masked unit listing unavailable"
printf "\n%.0s" {1..3}
# --- 4.8 SYSTEMD JOBS ---
echo "4.8 SYSTEMD JOBS"
systemctl list-jobs --no-pager 2>/dev/null || echo "No pending systemd jobs or listing unavailable"
printf "\n%.0s" {1..3}
# --- 4.9 BOOT CRITICAL CHAIN ---
echo "4.9 BOOT CRITICAL CHAIN"
if command -v systemd-analyze >/dev/null 2>&1; then
systemd-analyze critical-chain --no-pager 2>/dev/null | head -50
else
echo "systemd-analyze not installed"
fi
printf "\n%.0s" {1..3}
# --- 4.10 LONG-RUNNING STARTUP UNITS ---
echo "4.10 LONG-RUNNING STARTUP UNITS"
if command -v systemd-analyze >/dev/null 2>&1; then
systemd-analyze blame 2>/dev/null | head -30
else
echo "systemd-analyze not installed"
fi
printf "\n%.0s" {1..3}
# --- 4.11 SYSTEMD TIMERS ---
echo "4.11 SYSTEMD TIMERS"
systemctl list-timers --all --no-pager 2>/dev/null || echo "Systemd timer listing unavailable"
printf "\n%.0s" {1..3}
# --- 4.12 RECENT SYSTEM ERRORS ---
echo "4.12 RECENT SYSTEM ERRORS"
if command -v journalctl >/dev/null 2>&1; then
journalctl -p err -b --no-pager 2>/dev/null | tail -n 50
else
echo "journalctl not available"
fi
printf "\n%.0s" {1..3}
# --- 4.13 RECENT SERVICE RESTART ACTIVITY ---
echo "4.13 RECENT SERVICE RESTART ACTIVITY"
if command -v journalctl >/dev/null 2>&1; then
journalctl -b --no-pager 2>/dev/null | grep -Ei 'Started |Stopped |Starting |Stopping |Failed to start|Main process exited|Scheduled restart job' | tail -n 80 || \
echo "No recent service restart activity found"
else
echo "journalctl not available"
fi




