The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
mail from unix zedex Shell Programming and Scripting 6 05-01-2008 09:23 AM
mail in unix murad.jaber SUN Solaris 1 01-07-2008 10:07 AM
I am not able to send mail form unix to other mail accounts. chinnigd UNIX for Dummies Questions & Answers 1 04-06-2006 08:31 AM
can not send mail from unix server to company/yahoo mail b5fnpct UNIX for Dummies Questions & Answers 5 11-22-2002 09:24 PM
Unix Mail bobmking UNIX for Dummies Questions & Answers 6 06-07-2001 04:51 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-24-2009
avik.nandi avik.nandi is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 9
Unix Mail Box

Hi Friends,

I'm new to Unix. I have a fbackup step like
/bin/nice /etc/fbackup -f /dev/rmt/0m -i / -I /opt/monitrol/tmp/Index.full
2 > /var/adm/error.log
the errors for this step is redirected to a log file. How can I make to trigger mails when error occurs.

Please suggest.

Thanks in adavnce,

Avik.
  #2 (permalink)  
Old 02-25-2009
rikxik's Avatar
rikxik rikxik is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 250
I assume the script fails when error ocurrs. Then you can check the return code of the fbackup command ($?) and do what you need to do.

Code:
/bin/nice /etc/fbackup -f /dev/rmt/0m -i / -I /opt/monitrol/tmp/Index.full
2 > /var/adm/error.log
if [ $? -ne 0 ] ; then
    echo "Some error occurred [Error code=$?]"
    # steps you may want to add like sending mail etc.
fi
  #3 (permalink)  
Old 02-25-2009
avik.nandi avik.nandi is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 9
Thanks for your reply. But I'm still in the doubt how to send the mail, I mean to say please help me with a sample mail script which will fire on a condition of standard error 2.

/bin/nice /etc/fbackup -f /dev/rmt/0m -i / -I /opt/monitrol/tmp/Index.full
2 > /var/adm/error.log
if [ $? eq 2 ] ; then
  #4 (permalink)  
Old 02-25-2009
rikxik's Avatar
rikxik rikxik is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 250
Code:
if [ $? -eq 2 ] ; then
# Make sure you don't put space etc. before the next three lines. Tabs are ok.
mailx -s "Test mail" avik.nandi@wherever.com <<-MAIL
Error happend in fbackup
MAIL
fi
  #5 (permalink)  
Old 02-25-2009
avik.nandi avik.nandi is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 9
Thanks a lot friend. But to send a mail, how i need to configure my smtp server.

By using like you said

if [ $? -eq 2 ] ; then
# Make sure you don't put space etc. before the next three lines. Tabs are ok.
mailx -s "Test mail" avik.nandi@wherever.com <<-MAIL
Error happend in fbackup
MAIL
fi

will it work ? Actually, I'm very new to unix and novice, so please help me.

Thanks a lot once again.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:31 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0