#!/usr/bin/env bash # Diagnostic de lecture seule. Les échecs de lecture restent visibles. set -uo pipefail status=0 section() { printf '\n=== %s ===\n' "$1"; } read_command() { if ! "$@"; then printf '[!] Lecture échouée : %s\n' "$1" >&2; status=1; fi } top_processes() { if ! ps -eo pid,comm,%cpu,%mem,rss "--sort=$1" | sed -n '1,20p'; then printf '[!] Lecture échouée : ps (%s)\n' "$1" >&2 status=1 fi } service_state() { local scope="$1" unit="$2" enabled active rc=0 local prefix=(systemctl) [[ "$scope" == user ]] && prefix+=(--user) enabled="$("${prefix[@]}" is-enabled "$unit" 2>/dev/null)" || rc=$? case "$enabled" in enabled|disabled|static|masked|indirect|generated|linked|linked-runtime|alias|enabled-runtime|transient) ;; *) enabled="ERREUR($rc)"; status=1 ;; esac rc=0 active="$("${prefix[@]}" is-active "$unit" 2>/dev/null)" || rc=$? case "$active" in active|inactive|failed|activating|deactivating|reloading|maintenance) ;; *) active="ERREUR($rc)"; status=1 ;; esac printf '%-36s enabled=%-16s active=%s\n' "$unit" "$enabled" "$active" } section CHARGE; read_command uptime section MÉMOIRE; read_command free -h; read_command swapon --show section PRESSION for file in /proc/pressure/cpu /proc/pressure/memory /proc/pressure/io; do printf '%s\n' "--- $file"; read_command cat "$file" done section DISQUE read_command df -h / # Aucun prompt : la lecture privilégiée refusée est rapportée, jamais contournée. read_command sudo -n btrfs filesystem usage / section 'TOP CPU'; top_processes -%cpu section 'TOP RAM'; top_processes -rss section 'SERVICES EN ÉCHEC' read_command systemctl --failed read_command systemctl --user --failed section 'SERVICES À LA DEMANDE' for unit in vmware-networks.service vmware-usbarbitrator.service smb.service nmb.service; do service_state system "$unit"; done service_state user protonmail-bridge.service section 'PROCESSUS OBSERVÉS (qualification manuelle)' if pgrep -a -f 'nextcloud|thunderbird|protonmail-bridge|/protonmail/bridge|proton-pass|ollama|llama-server'; then : else rc=$? if (( rc == 1 )); then echo 'Aucun processus correspondant observé.' else printf '[!] Recherche de processus échouée (%s).\n' "$rc" >&2; status=1; fi fi section BATTERIE if [[ -r /sys/class/power_supply/BAT1/charge_control_end_threshold ]]; then read_command cat /sys/class/power_supply/BAT1/charge_control_end_threshold else echo 'Seuil BAT1 indisponible ou illisible ; état non établi.' fi section DÉMARRAGE read_command systemd-analyze read_command systemd-analyze blame exit "$status"