Visit Our UNIX and Linux User Community


help with alarming script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help with alarming script
# 1  
Old 09-02-2009
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
# 2  
Old 09-02-2009
Quote:
Originally Posted by jeffersno1
Code:
if [ $(grep "01db_up" monitor/results|grep FAIL|wc -l) -eq 1 ] ; then

See UUOC
Code:
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 [code] and [/code] 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
# 3  
Old 09-02-2009
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

Code:
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
# 4  
Old 09-02-2009
Quote:
Originally Posted by jeffersno1
I was thinking.. would it be better to put the output of the command into a variable.
Yes, if you want to reuse the value.
# 5  
Old 09-03-2009

You probably only need one of the two tests:

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

# 6  
Old 09-03-2009
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

Previous Thread | Next Thread
Test Your Knowledge in Computers #406
Difficulty: Medium
Cygwin was originally developed by Cygnus Solutions, which was later acquired by Microsoft.
True or False?

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

2. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

3. UNIX for Dummies Questions & Answers

Calling a script from master script to get value from called script

I am trying to call a script(callingscript.sh) from a master script(masterscript.sh) to get string type value from calling script to master script. I have used scripts mentioned below. #masterscript.sh ./callingscript.sh echo $fileExist #callingscript.sh echo "The script is called"... (2 Replies)
Discussion started by: Raj Roy
2 Replies

4. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

5. 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

Featured Tech Videos