Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Ubuntu: I am trying to send an email with sendmail, mailx, or mail (anything that will work). I am trying to send the contents of a log file as the message. Log located at /var/log/nginx/error.log.

I am running a cron every hour to see if anything in the error log changed and if it has I am trying to send the error log to myself in an email. A regular test with sendmail and mailx and mail work just fine for me.

This works (but not what I want):
echo "My test email being sent from sendmail" | /usr/sbin/sendmail email@gmail.com

I tried the following (none of them work for me):
sendmail email@gmail.com < /var/log/nginx/error.log,
/var/log/nginx/error.log | /usr/sbin/sendmail email@gmail.com,
cat /var/log/nginx/error.log | /usr/sbin/sendmail email@gmail.com,
mailx email@gmail.com < /var/log/nginx/error.log,
cat /var/log/nginx/error.log | mailx email@gmail.com
Obviously a newbie here.

share|improve this question
    
You don't expect many errors. If you had a real problem, your error log will grow to big to send by email. Rather think about sending only the last few kB. –  Lorenz Meyer Sep 12 '13 at 18:07
    
What Lorenz said. You might want to consider something like LogWatch instead. –  Katherine Villyard Sep 12 '13 at 18:26
add comment

1 Answer 1

Sendmail expects to get email headers and body over its stdin.
[email headers + empty line + email body ]
Your attempts failed to provide headers.

Try the script below:

#!/bin/sh
( 
   echo subject: /var/log/nginx/error.log
   echo  
   cat /var/log/nginx/error.log 
) | sendmail -i email@gmail.com 
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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