Operating System - HP-UX
1826004 Members
3289 Online
109690 Solutions
New Discussion

Re: sending mail message to root from a script

 
SOLVED
Go to solution
Ed Hon
Regular Advisor

sending mail message to root from a script

Within a shell script, how do I send a mail message to root? Thanks.
4 REPLIES 4
Kofi ARTHIABAH
Honored Contributor
Solution

Re: sending mail message to root from a script

take your pick:

echo " your message in here ....." | mail root

or
some_command | mail root
or
cat - << EOM | mail root
This
that
and the other line
to
root
EOM

etc.
nothing wrong with me that a few lines of code cannot fix!
Antoanetta Naghiu
Esteemed Contributor

Re: sending mail message to root from a script

The easiest way: as from command line:
mailx -s subject root@boxname.domaniename < message/or/filename
James R. Ferguson
Acclaimed Contributor

Re: sending mail message to root from a script

Ed:

...and if you would like to foward other account's mail (such as generated during cron tasks) to root, create /.forward with the list of accounts (one-per-line) that should forward their mail to root.

...JRF...

Rick Garland
Honored Contributor

Re: sending mail message to root from a script

You might also want to use aliases (another option to the /.forward file).
In this way, mail that is sent to root will be aliased to your account.

As opposed to checking the root mail on multiple servers, all servers send the root mail to your mailbox.