help with alarming script

hi,

im trying to setup a script which can look at a file and email me when a fail is present, this runs on cron every 10 minutes

Below is the file that will tell me if a PASS or FAIL has occured
$more monitor/results
Test: 01db_up.sh. Status: PASS. Message: db is up
Test: 02cm_up.sh. Status: PASS. Message: CM is running
Test: 03free_db.sh. Status: PASS. Message: 15% free space in data db
Test: 04free_log.sh. Status: PASS. Message: 99% free space in log db

currently i have this script

# Version - V0.1 19/08/09
#!/bin/ksh -xv

#test to see if the database is up and running
if [ $(grep "01db_up" monitor/results|grep FAIL|wc -l) -eq 1 ] ; then

mailx -s "Sybase Alert" my.email@host.co.uk
else
fi

// the above works great but i just need to know how to set up a better script

How can i start to make this better, what else would i put in the else statement apart from nothing!!!

any advise is greatly appreciated

Jeffers

See UUOC

if [ $($(grep -c 01db_up.*FAIL monitor/results) -ne 0 ] ; then

To keep the forums high quality for all users, please take the time to format your posts correctly.

  1. Use Code Tags when you post any code or data samples so others can easily read your code.
    You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags and by hand.)
  2. Avoid adding color or different fonts and font size to your posts.
    Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
  3. Be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
Reply With Quote

Thanks for your reply danmero

I was thinking.. would it be better to put the output of the command into a variable.

I'm new to scripting and i'm trying to get my head around it all.

is there anything wrong in do the following

01db_up="grep -c 01db_up.*FAIL monitor/results"

if [ $01db_up = -eq 1 ] ; then
statement

is it not better to assign each test to a variable then maybe do a while test = 0 do nothing, if test = 1 then do do something??

this is what I'm finding difficult.

How would i achieve something like this and is it good practice?

thanks again

Jeffers

Yes, if you want to reuse the value.

You probably only need one of the two tests:

if grep -e "01db_up.*FAIL" -e "FAIL.*01db_up" monitor/results  ; then
   mailx -s "Sybase Alert" my.email@host.co.uk
fi

can you explain what the "01db_up.*FAIL" mean

is this saying that FAIL has to exist on the same line as 01db_up. whats the significance of the . before the *

many thanks

Jeffers