Auto-detect sendmail/msmtp for email notifications
Resolve the mailer binary at job creation time and bake the full path into the service file, so it works regardless of PATH in the systemd service environment. Warns and skips if neither is found. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
98b180a912
commit
c3c534f7ce
1 changed files with 4 additions and 1 deletions
5
systab
5
systab
|
|
@ -283,8 +283,11 @@ ExecStopPost=/bin/sh -c 'if [ "\$SERVICE_RESULT" = success ]; then icon=dialog-i
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
if [[ -n "$email" ]]; then
|
if [[ -n "$email" ]]; then
|
||||||
|
local mailer
|
||||||
|
mailer=$(command -v sendmail || command -v msmtp || true)
|
||||||
|
[[ -n "$mailer" ]] || { warn "No sendmail or msmtp found, skipping email notification"; return; }
|
||||||
cat >> "$file" <<EOF
|
cat >> "$file" <<EOF
|
||||||
ExecStopPost=/bin/sh -c 'if [ "\$SERVICE_RESULT" = success ]; then s=completed; else s="failed (\$EXIT_STATUS)"; fi; printf "Subject: systab: $short_id %s\\n\\n%s at %s\\n" "\$s" "\$s" "\$(date)" | sendmail $email'
|
ExecStopPost=/bin/sh -c 'if [ "\$SERVICE_RESULT" = success ]; then s=completed; else s="failed (\$EXIT_STATUS)"; fi; printf "Subject: systab: $short_id %s\\n\\n%s at %s\\n" "\$s" "\$s" "\$(date)" | $mailer $email'
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue