Using mailx in a bash script running under systemd

119 views Asked by At

I am trying to get a bash script that sends email with attachment to be executed by systemd. Running the script from the command line works fine, but when systemd runs it, the mailx command does not send the email.

# email report
/usr/bin/mailx -a $OUTFILE -s "SYSTEM REPORT `date '+%A, %B %d, %Y'`" \
   "[email protected]"  << EOF
System report attached
EOF

My .service file contains this:

[Service]
User=myuser
Group=mygroup
ExecStart=/usr/bin/bash -c '/home/myuser/bin/system.bash' 
WorkingDirectory=/home/myuser

My environment is Fedora 37, x86_64. All software is current. I tried a few things, like removing the attachment and the date in the mail subject line, but I can't get past that it all works running from command line, and only mailx fails with systemd. No errors or other messages with journalctl.

Any assistance would be appreciated.

0

There are 0 answers