I’m trying to have mailx send an email alert before system shutdown/reboot using systemd service:
My unit file executes properly on shutdown (logs shows the script being executed), but I never get the email.
My understanding is that mailx simply queues the messages for MTA (sendmail?) to be processed, hence I use sendmail.service in the After.
I’ve tested tons of different variations but can’t make it send the email. Seems like the email pipeline is interrupted at some point before my script gets executed.
pre-shutdown.sh in essence contains one command (simplified for brevity, and it works if I run it from terminal manually):
cat "$BODY" | mailx <params> email@example.com
This is my Unit file:
[Unit] Description=Send email alert just before shutdown #Requires=network.target sendmail.service After=network.target After=sendmail.service [Service] Type=oneshot RemainAfterExit=true ExecStop=/path/pre-shutdown.sh [Install] WantedBy=multi-user.target
What am I missing?