I guess writing this up was therapeutic. :-)

Getting mail to work from within the script was a matter using double
quotes -- instead of...

/sbin/ifconfig | mail -s $CURRTIME-$DYNIPADDR [EMAIL PROTECTED]

...using...

/sbin/ifconfig | mail -s "$CURRTIME-$DYNIPADDR" [EMAIL PROTECTED]

...got it to work.

As for concatenating variables, the following worked...

SUBJECT="$CURRDATE"'-'"$DYNIPADDR"

...allowing me to use...

/sbin/ifconfig | mail -s $SUBJECT [EMAIL PROTECTED]

...in the script without errors.

I haven't figured out how to get elm to send without echoing "Sending
mail..." yet, so if anyone has the answer to that, I'm still listening.

bd


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Brad Doster
Sent: Saturday, December 09, 2000 2:16 PM
To: [EMAIL PROTECTED]
Subject: Auto-mail Script Woes


I have a client running RH 6.2 as a DSL router.  The DSL address is dynamic,
so to keep tabs on the system, I have a cron script that sends me its
ifconfig once per hour.  I'm trying to get mail or elm to use a subject line
like...

001209_1315-200.200.200.200

...where 001209 is the date sent, 1315 is time sent and 200.200.200.200 is
the current IP address of the system.  The goal is to be able to sort by
subject so that I can easily check that the messages were sent when they
were intended to be.

In my script I have variables which are defined at run time.  Examples are
$CURRTIME=001209_1315 and $DYNIPADDR=200.200.200.200.  The script line that
sends the mail is:

/sbin/ifconfig | mail -s $CURRTIME-$DYNIPADDR [EMAIL PROTECTED]

When the above is run from a shell prompt, it works fine.  When it's run
from within a script, $DYNIPADDR is treated as the first "To:" address,
resulting in "User unknown" errors, i.e. it tries to send to
200.200.200.200, *and* to [EMAIL PROTECTED]  I've tried other delimiters
between the variables (":" and "_") with similar results. Why does mail
behave one way from the shell prompt, and differently from within a script?

One workaround might be to combine the two variables into one, say $SUBJECT,
but I haven't been successful in figuring out how to do that -- any help
appreciated here.  I suspect it's a simple thing, but I'm rather new a
writing bash scripts, let alone using sed or awk.

Workaround #2 is to use elm rather than mail.  This works, but elm insists
on echoing "Sending mail...".  That becomes a problem when run from a cron
job, as there's noone logged in, so no console to echo to, so for each
message sent, I get another message containing the text "Sending mail..."
and nothing else.

A "bandaid" to the elm problem is to create an inbox rule which deletes the
extra messages, but I'd much rather learn how to do this correctly.

TIA for any assistance!

bd

===========================
Brad Doster
Insight Network Solutions
www.InsightNetSolutions.net
925.335.9510




_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list



_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to