Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending mail from a shell script

Status
Not open for further replies.

mayh3m

Technical User
Jul 12, 2002
84
ZA
I have the following script which send get variables from mrtg and then sends mail using the /bin/mail program. The only problem is the mail is sent by root. How can i change this script so that the mail comes from another address? Please help!

###########################################################
#!/bin/sh
if [ $1 == "172.28.1.1_MTA" ] ; then
DEST=&quot;<user@mail.co.za>&quot;
else
DEST=&quot;<user@mail.co.za; user1@mail.co.za; user3@mail.co.za>&quot;
fi
( echo &quot;Load on $1 currently $3, but should be not more than $2.&quot;
echo &quot;See &quot;) |mail -s &quot;load on $1&quot; $DEST

##########################################################
 
Presumably the script is owned and run by root? Could it be changed so that someone else owns it and runs it, thus using their mail id? What is the problem with having it orginate from root anyway?
 
Its not that it is such a big issue. Its just that the mail is being sent out to clients and it must look professional. I would like it to look like it is coming from monitor@domain.co.za. Unfortuneately, the program is run by root which can't be changed. It is this that triggers the script. I can't change that.
 
You could use mailx instead - same as mail but with extra commands

mailx -r &quot;return@address&quot; -s &quot;load on $1&quot; $DEST

If you have mailx, that is...

Only other way could be to run it through sendmail directly, as in
Code:
{
  echo To: $DEST
  echo &quot;From: $FROM&quot;
  echo
  echo &quot;load on ....&quot;
} | /usr/lib/sendmail -oi -t

You may have to check your sendmail flags, but on my system these mean
-oi - set value i - which means ignroe dots in incoming message
-t - scan messages to check who to send to

N.
 
Excuse my ignorance. It seems to be trying to send the mail. Although it seems to have a problem with the addresses. It gives me this error:
Following addresses (lists addresses)had permanent fatal errors.
(reason: 553 malformed address:

Is it because of the format of the multiple addreses? How do i correct this?

This is what the script looks like now

#!/bin/sh
if [ $1 == &quot;172.28.1.1_MTA&quot; ] ; then
DEST=&quot;<bbaker@fnb.co.za>&quot;
else
DEST=&quot;<bbaker@address.co.za; jvheerden@address.co.za; jhendricks@address.co.za; dcouto@address.co.za; 0837070733@sms.fnb.co.za>&quot;
fi
{
echo To: $DEST
echo &quot;From: mrtg@address.co.za&quot;
echo
echo &quot;Subject: Traffic on $1 bad&quot;
echo &quot;Traffic on $1 currently $3, but should be not more than $2&quot;
} | /usr/lib/sendmail -oi -t

Thanks for your help
 
Use commas not semi-colons (that is an Outlook standard, not a 'real standard' ;o)

N.
 
Hi naggiman

Thanks very much for all your help. It works......the only problem is that the mail sits in the sendmail queue and doesn't get sent unless I flush the queue. When i flush it, the mail is delivered without any problems. Any idea what could cause this? The script is to alert people of problems, so it has to be sent instantaneously.

You seem very clued up and that is why I'm asking.

Regards
Brendon
 
Can you provide a few more details, such as sendmail version, whether sendmail is daemon or run by cron, platform, etc?

Have a look in your sendmail.cf file as this is possibly where it is configured for this behaviour you are seeing (/etc/mail/sendmai.cf?).

If it comes to it, you can always flush the sendmail queue as part of your script. Not necessarily the best way of doing it, however, but it is a work-around.

N.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top