5

How to send some text in email along with the contents of the file, don't want to send file as an attachment? is it possible via mailx command?

mailx -s "Email log file" abc@mail.com <$log_file;

$log_file contents gets emailed but below doesn't work

echo "Comment: log contains last month report" | mailx -s "Email log file" abc@mail.com < $log_file

Needed output in email:

Comment: Log contains last month report

 <All contents of $LOG_FILE as text>
homer
  • 423
  • 2
  • 11
  • 24
  • 1
    Probably duplicate of http://stackoverflow.com/questions/2282506/how-can-i-send-an-email-through-unix-mailx-command. At least, that link answers the question – mpez0 Jan 20 '15 at 22:15

1 Answers1

2

Here is how you would do it:

echo "Comment: log contains last month report\n $(cat \$log_file)" | mailx -s "Email log file" abc@mail.com

The only thing "funny" is you'll have to escape that $ in the filename. You can also add more new lines \n if need be.

JeffM
  • 365
  • 1
  • 5
  • 10