Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to send "mail", with no body, from within a UNIX script

2,687 views
Skip to first unread message

bfog

unread,
Jan 20, 2010, 11:50:10 AM1/20/10
to
I created a script to monitor the number of sessions in an Oracle
database. When the number of sessions exceeds a threshold I use a UNIX
"mail" command to send an email message, and an electronic page.
Everything to need to know is contained in the subject line. I have no
need to send text in the body of the message. The only way I have
found to make the command work without errors is to load the body with
a file that contains a single space. I tried "</dev/null" but that did
not work. Does anyone have a suggestion on how I can use "mail"
without putting anything in the body?

I know the code below works, but I do not want to employ the empty
file, "admtest_session_empty_file.lst".

#Send a message if the session count is high.
if [ $count_sessions -gt 60 ]
then
mail -s "INSTANCE sessions high: $count_sessions"
xxx...@xxxxx.com yyy...@yyypage.yyyy.com zzz...@zzzzz.com
<admtest_session_empty_file.lst
fi

Thank you,
Bill

Alvin Andries

unread,
Jan 20, 2010, 2:05:54 PM1/20/10
to

Hi Bill,

My first reaction would be to use\
echo | mail -s ...
which should send an e-mail with just an empty line as body. You could
alse experiment with "echo -n" and see how mail reacts.

Regards,
Alvin.

Henry

unread,
Jan 20, 2010, 2:15:50 PM1/20/10
to
On Jan 21, 5:50 am, bfog <bfoga...@gaports.com> wrote:
> I created a script to monitor the number of sessions in an Oracle
> database. When the number of sessions exceeds a threshold I use a UNIX
> "mail" command to send an email message, and an electronic page.
> Everything to need to know is contained in the subject line. I have no
> need to send text in the body of the message. The only way I have
> found to make the command work without errors is to load the body with
> a file that contains a single space. I tried "</dev/null" but that did
> not work. Does anyone have a suggestion on how I can use "mail"
> without putting anything in the body?
>
> I know the code below works, but I do not want to employ the empty
> file, "admtest_session_empty_file.lst".
>
> #Send a message if the session count is high.
> if [ $count_sessions -gt 60 ]
> then
>     mail -s "INSTANCE sessions high: $count_sessions"
> xxxx...@xxxxx.com yyy...@yyypage.yyyy.com zzzz...@zzzzz.com

> <admtest_session_empty_file.lst
> fi
>
> Thank you,
> Bill

use Nagios - it's free :)

wisnios

unread,
Jan 20, 2010, 5:28:35 PM1/20/10
to
Hello Bill.

Try this:

$ true | mail -s "no body just subject" wis...@gmail.com
Null message body; hope that's ok

Kind regards.
Marcin

bfog

unread,
Jan 21, 2010, 10:24:47 AM1/21/10
to
On Jan 20, 11:50 am, bfog <bfoga...@gaports.com> wrote:
> I created a script to monitor the number of sessions in an Oracle
> database. When the number of sessions exceeds a threshold I use a UNIX
> "mail" command to send an email message, and an electronic page.
> Everything to need to know is contained in the subject line. I have no
> need to send text in the body of the message. The only way I have
> found to make the command work without errors is to load the body with
> a file that contains a single space. I tried "</dev/null" but that did
> not work. Does anyone have a suggestion on how I can use "mail"
> without putting anything in the body?
>
> I know the code below works, but I do not want to employ the empty
> file, "admtest_session_empty_file.lst".
>
> #Send a message if the session count is high.
> if [ $count_sessions -gt 60 ]
> then
>     mail -s "INSTANCE sessions high: $count_sessions"
> xxxx...@xxxxx.com yyy...@yyypage.yyyy.com zzzz...@zzzzz.com

> <admtest_session_empty_file.lst
> fi
>
> Thank you,
> Bill


Thank you Alvin, Henry, and Marcin.

I tried both echo and true. What worked for me was:
echo|mail –s “message text” xxxx...@xxxxx.com yyy...@yyypage.yyyy.com
zzzz...@zzzzz.com

The message created with:
true|mail –s “message text” xxxx...@xxxxx.com yyy...@yyypage.yyyy.com
zzzz...@zzzzz.com
produced an email that look good, but the electronic page included the
following message body:
“<html><body></body></html>”
That matched the results produced by using the mail command alone, and
omitting any reference to the body.

Thank you all for your suggestions.
Bill

0 new messages