From 1a00e3cfaa7c467dce9a6f0015385015fa30897c Mon Sep 17 00:00:00 2001 From: Patrick Lewis <4015312+locus313@users.noreply.github.com> Date: Sat, 10 Oct 2026 16:20:35 -0700 Subject: [PATCH] fix(monitor-cpu-load): find plesk under cron and survive empty owner map Cron's PATH lacks /usr/sbin, so plesk was not found and the subscription map was empty. The FNR == NR awk idiom then consumed the CPU file as the map, hiding all CPU rows and skipping log analysis. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- monitor-cpu-load/monitor-cpu-load.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/monitor-cpu-load/monitor-cpu-load.sh b/monitor-cpu-load/monitor-cpu-load.sh index f5de2d6..3cb294c 100755 --- a/monitor-cpu-load/monitor-cpu-load.sh +++ b/monitor-cpu-load/monitor-cpu-load.sh @@ -262,6 +262,10 @@ fi # MAIN SCRIPT CONFIGURATION ############################################################################### +# Cron's default PATH lacks /usr/sbin and /usr/local/sbin, where plesk and fail2ban-client live +PATH="${PATH}:/usr/local/sbin:/usr/sbin:/sbin" +export PATH + EMAIL_TO="${EMAIL_TO:-}" LOAD_THRESHOLD_FACTOR="${LOAD_THRESHOLD_FACTOR:-1.0}" WINDOW_MINUTES="${WINDOW_MINUTES:-30}" @@ -466,7 +470,7 @@ collect_cpu() { log_message "WARNING: plesk CLI not found, CPU cannot be attributed to subscriptions" fi - awk -F'\t' 'FNR == NR { owner[$1] = $2; next } + awk -F'\t' 'FILENAME == ARGV[1] { owner[$1] = $2; next } { split($0, f, " "); name = (f[1] in owner) ? owner[f[1]] : f[1]; cpu[name] += f[2]; mapped[name] = (f[1] in owner) } END { for (k in cpu) printf "%s %.1f %d\n", k, cpu[k], mapped[k] }' \ "${WORK}/login2sub" "${WORK}/proc_user_cpu" | sort -k2,2nr > "${WORK}/sub_cpu"