#!/usr/bin/env bash set -euo pipefail usage() { echo "Использование: audit_systemd_timers.sh [--limit N]" } limit=50 while [[ $# -gt 0 ]]; do case "$1" in --limit) limit="${2:-50}"; shift 2 ;; -h|--help) usage; exit 0 ;; *) echo "Неизвестный аргумент: $1" >&2; usage >&2; exit 2 ;; esac done [[ "$limit" =~ ^[0-9]+$ ]] || { echo "--limit должен быть числом" >&2; exit 2; } command -v systemctl >/dev/null 2>&1 || { echo "systemctl не найден" >&2; exit 2; } echo "== Все таймеры ==" timers="$(systemctl list-timers --all --no-pager --no-legend 2>/dev/null || true)" if [[ -n "$timers" ]]; then printf '%s\n' "$timers" | head -n "$limit" else echo "Таймеры не найдены." fi echo echo "== Включённые таймеры ==" systemctl list-unit-files --type=timer --state=enabled --no-pager --no-legend 2>/dev/null | head -n "$limit" || true echo echo "== Неудачные таймеры ==" systemctl list-units --type=timer --state=failed --no-pager --no-legend 2>/dev/null || true echo echo "== Запуск из временных каталогов ==" found=0 while IFS= read -r line; do echo "$line" found=$((found + 1)) (( found >= limit )) && break done < <(grep -RInE 'ExecStart=.*(/tmp/|/var/tmp/|/dev/shm/)' /etc/systemd/system /usr/lib/systemd/system 2>/dev/null || true) echo "Найдено строк: $found" echo echo "== Таймеры с правами записи для всех ==" if [[ -d /etc/systemd/system ]]; then find /etc/systemd/system -maxdepth 2 -name '*.timer' -perm -0002 -print 2>/dev/null || true fi