If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > shell scripting question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-27-04, 10:51
telemorgan telemorgan is offline
Registered User
 
Join Date: Jan 2004
Posts: 5
shell scripting question

I am trying to write a monitoring program that will send an email if it cannot do a tnsping to a database. I have a number of database names that I want to run the command on. How can I write a script to do this. I know I can write an if statement for each var but I think there should be an easier \ cleaner way. For example:

-----------------------------------------------------------------------------
DB1=test

DB_VAR=`tnsping $DB1 | grep OK | awk -F ' ' '{print $1}'`

if [ DB_VAR =! "OK" ]; then
echo "Something is messed up with the database" | mail blah@blah.com
fi

How can I do this with a number of different database names?
Reply With Quote
  #2 (permalink)  
Old 01-27-04, 11:23
sushant sushant is offline
Registered User
 
Join Date: Jan 2004
Posts: 49
Re: shell scripting question

Quote:
Originally posted by telemorgan
I am trying to write a monitoring program that will send an email if it cannot do a tnsping to a database. I have a number of database names that I want to run the command on. How can I write a script to do this. I know I can write an if statement for each var but I think there should be an easier \ cleaner way. For example:

-----------------------------------------------------------------------------
DB1=test

DB_VAR=`tnsping $DB1 | grep OK | awk -F ' ' '{print $1}'`

if [ DB_VAR =! "OK" ]; then
echo "Something is messed up with the database" | mail blah@blah.com
fi

How can I do this with a number of different database names?
assume that you have list of dbnames in file dbnames.txt (with each dbname on separate line)

for DB1 in `cat dbnames.txt`
do

DB_VAR=`tnsping $DB1 | grep OK | awk -F ' ' '{print $1}'`

if [ DB_VAR =! "OK" ]; then
echo "Something is messed up with the database" | mail blah@blah.com
fi

done
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On