Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

I tried the following (none of them work for me):
sendmail < /var/log/nginx/error.log,
/var/log/nginx/error.log | /usr/sbin/sendmail,
cat /var/log/nginx/error.log | /usr/sbin/sendmail,
mailx < /var/log/nginx/error.log,
cat /var/log/nginx/error.log | mailx
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

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:

   echo subject: /var/log/nginx/error.log
   cat /var/log/nginx/error.log 
) | sendmail -i 
share|improve this answer

Your Answer


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.