Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 11100  / 1 Year ago, fri, may 26, 2023, 2:16:16

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



   /usr/sbin/sendmail [email protected]<<EOF
subject:Backup Error!
from:backup@server01
$error
EOF


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!
from:backup@server01
$error
EOF
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?


More From » bash

 Answers
4

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 -- [email protected] <<EOF
subject: Backup Error!
from:backup@server01

$error
EOF

[#28772] Saturday, May 27, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ledeball

Total Points: 434
Total Questions: 121
Total Answers: 120

Location: Antigua and Barbuda
Member since Sat, Apr 24, 2021
3 Years ago
;