1

I am writing a script that sends log files via the terminal to my email address. It appears, that when I'm using the -A flag, the message itself does not show in the email.

echo "This is the message I want to be shown in the email, but it does not appear." | mail -s "any subject" -A <path to attachement> mail@example.com

Here is a snippet from the script that may make the situation clearer:

mail='mail@example.com'
log="/var/log/apt/$(date +"%Y%m%d")-apt-update.log"
echo "Update done" | mail -s "update done" -A $log $mail

When I am sending the mail without -A and without the attachment (only with the subject) then the message I am echoing does appear.

Any ideas?

Thanks in advance.

1

This works for my daily backup:

mail -a "$Filename64" -s "$Filename64" "$EmailAddr" < BackupLog

So for your case try:

mail='mail@example.com'
log="/var/log/apt/$(date +"%Y%m%d")-apt-update.log"
echo "Update done" > /tmp/MessageBody
mail -a "$log" -s "update done" "$mail" < /tmp/MessageBody
| improve this answer | |
  • Unfortunately this does not work for me either. There is still no message in the mail. And I guess the flag u meant was '-A'. Since '-a' is for appending headers. – Pacha Sep 6 '19 at 5:41
  • I just noticed MessageBody was spelled wrong the second time. I've changed it. – WinEunuuchs2Unix Sep 6 '19 at 10:32
  • Must it be named 'MessageBody' or is it just for your example? – Pacha Sep 9 '19 at 10:24
  • Just my example where I had spelled it differently second time... – WinEunuuchs2Unix Sep 9 '19 at 10:34
  • Well i guess dumb question of me, tested it anyway with different spellings... sorry for that. Unfortunately this still does not work for me :( But it's actually not that important, just a "nice to have". Since those mails are just for me and for messing around with stuff. I guess I will just leave this issue for the moment. – Pacha Sep 9 '19 at 10:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.