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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need to write a script for sending email

Status
Not open for further replies.

siddhardha

Programmer
Feb 1, 2006
5
US
Hi All

I have one problem,i dont know about unix scripts,but i need to write one script in the input (return code != o)
then i need to send a mail to group,

some bady help me ,how i need to write script

thanks,
sid
 
well, in order to send an email from command line you can use:

cat mail.txt | mail -s "code is different to 0" group@company.com

where mail.txt is the mail letter (a text file obviously).

Cheers.

Chacal, Inc.[wavey]
 
you need to setup a alias with all the email addresses in it to send to a group. The file you edit is in /etc and is called aliases. After you add the addresses to it run sendmail -bi This will create the aliase database. Then the rest is simple.

sendmail -s "subject" alias < fileout put to mail

sendmail -s "test email" admin <test.txt
 
if u dont mine,i dont know any thing in unix ,if u guys have any sample scrips plz send to me
 
The return code of a command can be obtained from the special variable $?, so you can use something like:

Code:
(your job here)
RETURNCODE=$?
if [ $RETURNCODE -gt 0 ]
then
    echo | mail -s "your job failed, return code $RETURNCODE" recipient1@here.com,recipient2@there.com
fi

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top