Re: send email from commandline
On Tuesday 27 April 2004 17:00, Rick Weinbender wrote:
> What is the correct syntax for sending
> mail from the command line.
....
> mail -s "some subject" user1@domain.com
>
> I want to incorporate this into a script but when I enter it
> at the commandline it acts like it is needing more.
At the command-line it is waiting for the body of the message, which you
end with Ctrl-D or a line containing only the character ".". (Try it
and you'll see what I mean.)
Alternatively you can pipe STDOUT from another command or read the input
from a file, e.g.:
who | mail -s "who is here" user@example.com
mail -s "what I have been doing" user@example.com <~/.bash_history
In a script you could use either of these methods, or a "here document"
if the body is fixed:
mail -s "warning" user@example.com <<EOF
This is my standard warning.
EOF
The shell treats everything from the end of the line containing <<MARKER
as STDIN until it hits a line containing only MARKER. It's customary
but not obligatory to use "EOF" for this. (I don't know if there are
some reserved words that would break it. This << works on the
command-line as well as in a script, but I don't know why one would
want to.)
If you really want a message with an empty body, you can use /dev/null
to provide plenty of nothing:
mail -s "nothing to see here" user@example.com </dev/null
--
HTH,
Adam
Reply to: