How to create a script that will email once there is an error?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to create a script that will email once there is an error?
# 1  
Old 12-22-2011
How to create a script that will email once there is an error?

Hi Guys,

Good day ULF! Can you assist me in creating a script that will email once an error has occurred. It's like this, I have script that is used for monitoring, distinct keywords on the status are OK and Error respectively. Then I created another script that will call for the monitoring script to run so that the new script will save an output into a file. I call it as Status-Collector.sh and I will put it as an entry in cron. This is the sample output that has been generated:
Code:
Date Executed:
--------------
Thu Dec 22 13:30:54 EET 2011


Command Executed: <command-01>
------------------------------------------------------
SNMP Status = OK

Command Executed: <command-02>
--------------------------------------------------------
SYSTEM Status = OK

Command Executed: <command-03>
-----------------------------------------
DISKSPACE Status = OK

Command Executed: <command-04>
-------------------------------------------------------
TOTAL_USER Status = OK

Command Executed: <command-05>
---------------------------------------------------------------
VR_ROLE Status = OK

Command Executed: <command-06>
server0
--------------------------------------------------------------------------------
RDVR_ROLE Status = OK

Command Executed: <command-07>
------------------------------------------------------
SERVER_BOOT Status = OK

Command Executed: <command-08>
------------------------------------------------------------------------
RDSERVER_BOOT Status = OK

Command Executed: <command-09>
------------------------------------------------------
Error! High Load Average = 1.10 in server8 for the last 5-minutes.

NOTE: Logs can be found in /tmp directory with file extension name of .debug

I want a script that will read per line of the output file and will email if one or more Errors occurred.


Please advice,
rymnd_12345


BTW: I would like to personally thank Unix and Linux Forum, my respect and appreciation to all the members and "staffs" of this. I myself admit that I'm learning a lot each day. Thank you so much, keep-up the great work. God bless!
# 2  
Old 12-23-2011
Hi,

if I understood your post, the monitoring script logs an error message if an error condition is met.
why don't you make the monitoring script to also return an exit code other than 0 when the error condition occurs, so that the first script (that is, the script that calls the monitoring script) can just check the exit code of the second script and decide if sending an alert email is necessary or not? This way, the first script doesn't have to check for error entries in the log file.

see ya
fra
# 3  
Old 12-27-2011
Quote:
Originally Posted by rymnd_12345
I want a script that will read per line of the output file and will email if one or more Errors occurred.

Maybe you can try something like this,

read the output file containing logs

grep *Status = Error O/p Log file >temp_mail_file

then send mail containing body as temp_mail_file
with
/usr/lib/sendmail -t -oi <temp_mail_file

This will work in UNIX AIX version

Last edited by DukeNuke2; 12-27-2011 at 05:15 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to create runtime variables based on the number of parameters passed in the script

Hi All, I have a script which intends to create as many variables at runtime, as the number of parameters passed to it. The script needs to save these parameter values in the variables created and print them abc.sh ---------- export Numbr_Parms=$# export a=1 while do export... (3 Replies)
Discussion started by: dev.devil.1983
3 Replies

2. Shell Programming and Scripting

Script to create folder, copy file, and send email on success

I am very new to UNIX as well as scripting so please be gentle, haha. I have a Linux client which has a mount point mapped to my /etc folder on a NetApp FAS system. I woudl like to be able to copy the hosts and rc files once a week from the FAS to a different location for backup. When the... (4 Replies)
Discussion started by: minnino
4 Replies

3. Programming

CGI Perl script to execute bash script- unable to create folder

Hi I have a bash script which takes parameters sh /tmp/gdg.sh -b BASE-NAME -n 1 -s /source/data -p /dest/data/archive -m ARC gdg.sh will scan the /source/data and will move the contents to /dest/data/archive after passing through some filters. Its working superb from bash I have... (0 Replies)
Discussion started by: rakeshkumar
0 Replies

4. Homework & Coursework Questions

Create script to add user and create directory

first off let me introduce myself. My name is Eric and I am new to linux, I am taking an advanced linux administration class and we are tasked with creating a script to add new users that anyone can run, has to check for the existence of a directory. if the directory does not exist then it has... (12 Replies)
Discussion started by: pbhound
12 Replies

5. AIX

backup script failed with error '0403-005 Cannot create the specified file'

In AIX 5.1, a daily run script that backing up oracle data failed yesterday with following errors: The Tivoli backup of DBPROD failed. What could be the issue, OS, backup or Oracle? (3 Replies)
Discussion started by: jalite19
3 Replies

6. Shell Programming and Scripting

Script to send email after comparing the folder permissions to a certain permission & send email

Hello , I am trying to write a unix shell script to compare folder permission to say drwxr-x-wx and then send an email to my id in case the folders don't have the drwxr-x-wx permissions set for them . I have been trying to come up with a script for few days now , pls help me:( (2 Replies)
Discussion started by: nairshar
2 Replies

7. Shell Programming and Scripting

Create email Addresses

Hi, I own 2 websites 1world1game.com and thetoonarmy.net. I can access my 1world accont using mediatemples webmail. The problem i am having is that I want to allow users to register an email from a form on 1World1Game such as tom@thetoonarmy.net and be able to access it from 1world1game. ... (2 Replies)
Discussion started by: rmail2006
2 Replies

8. Shell Programming and Scripting

Send email on script error

I need to start off by saying that I am not much of a programmer and know enough to cause lots of trouble. I've been writing this script to decrypt an XML feed, then parse the feed into a database. The script is executed from cron. #!/bin/sh PGPPATH=/path/to/directory echo "pgp... (6 Replies)
Discussion started by: Aslan_Eident
6 Replies

9. Shell Programming and Scripting

create a shell script that calls another script and and an awk script

Hi guys I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file. #!/bin/sh echo " $2 $3 $4 $5 $6 $7 isql -w400 -U$2 -S$5 -P$3 << xxx use $4 go print"**Changes to the table... (0 Replies)
Discussion started by: magikminox
0 Replies

10. UNIX for Advanced & Expert Users

create email w/ ASCII attachment via command-line

All, I need to email an ASCII data file to a business partner, and intended on creating a Korn Shell script to create an email message (minimal text), and attach the ASCII data file to the email. It seems this is not as easy as I had thought it might be. sendmail does not support... (3 Replies)
Discussion started by: jwperry
3 Replies
Login or Register to Ask a Question