[Nottingham] e-mail from a shell...
Graeme Fowler
graeme at graemef.net
Wed Apr 21 17:04:37 BST 2004
On Wed, 21 Apr 2004, David Wolfson wrote:
> I've not had time to try the VPN yet, but have been trying to tidy up some
> other loose ends first. I've been sorting out some cron configurations, and
> am confused by the "MAILTO= " command.
Erm...
If, and only if, the cron jobs create any output on either stderr or stdout,
will crond email the address given in the MAILTO environment variable (not a
command).
For example, a cronjob like so:
MAILTO=user at domain.name
5 * * * * ls -lart /tmp/
Should spit out an email of the form:
-- cut here --
From: cronuser at server
To: <user at domain.name>
Subject: Cron <user at server> ls -lart /tmp/
-r--r--r-- 1 root root 11 Apr 21 08:03 .X0-lock
drwx------ 2 graeme graeme 147456 Apr 21 08:03 orbit-graeme
-- cut here --
And that would be it.
The 'mail' command is a very basic mail application. invoking 'mail' on its'
own gives you a command-line driven, basic mail reader. Doing something like:
echo "hello" | mail -s "mail test" user at server.domain.name
will email user at server.domain.name a message of subject "mail test", body a
single line "hello".
> I've also tried using the 'mail to' command in a shell, appears to work but
> never arrives.
That's because you're trying to send an email to a local user named "to".
Assuming you don't have one, your local mail spool should contain a bounce
message.
I'm guessing that I have to configure this command, but when
> I try and to a google/linux-questions search I get a huge list of peoples
> e-mail links. Not very helpful.
"man mail" is your friend :) as, in this case, is "man 5 crontab"...
> Am I barking in the wrong woods? Is it possible to send e-mail in the form
> I want from a shell script? If so, could anyone point me in the right
> direction? I'd like to be able to find out from my inbox if my cron jobs
> have run ok...
If they exit silently when they've completed with no errors, expect no emails
from cron :)
If you make them output a "job blah ran successfully" as the last part, you'll
get some output and therefore an email.
Of course, this is assuming that you have a sendmail (or exim, or similar)
binary for messages to be sent with. And that your box can do DNS lookups if
they're needed for remote mail!
HTH
Graeme
More information about the Nottingham
mailing list