Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

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

This is the code I have in a bash script that runs as a cronjob. The cronjob run as root.

   subject:Backup Error!

There is code after this and the email I get is as follows:

From the root user on the machine.

and the message includes:

   subject:Backup Error!
   More code...
   that is in the script
   all the way to the end...

I have tried other variations, this is the closest I've got. I tried this in a regular script and it worked properly. Whats going on, and how can I send this email, specifying the subject and form sender?

share|improve this question
up vote 2 down vote accepted

The previous answers have already mentioned:

  • bad end of "here document" (END)
  • missing empty line between headers and body

Additional fixes:

  • -i command line option to stop special treatment for lines starting with dot
  • -- to separate command line options from addresses of recipients (good style recomendation)

Corrected script:

/usr/sbin/sendmail -i -- <<EOF
subject: Backup Error!

share|improve this answer

I suggest you to not use any whitespace character in front or after the second limit string EOF. If you use just only one space in front or after the limit string, that special-purpose code block will never work. So, use only:


And you should read some bash scripting guides in this sense like Chapter 19. Here Documents.

share|improve this answer

Sendmail (and email in general, it seems) requires a blank line between headers and body. The following example worked.

$ sendmail <<EOF
> subject: testing
> from:
> This is my body!

(Obviously pasting that in with the >s in there won't work, just alter what you're doing so that there's a blank line between your headers and error message).

share|improve this answer
So simple. Thanks – dan08 Oct 24 '13 at 14:03

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.