SunQuest
           UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old January 27th, 2004, 09:38 AM
telemorgan telemorgan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 1 telemorgan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Simple 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 URL
fi

How can I do this with a number of different database names?

Reply With Quote
  #2  
Old January 27th, 2004, 11:19 AM
druuna druuna is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 137 druuna User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 37 sec
Reputation Power: 0
You could do the following:

Code:
DBs="test1 test2 test3 test4"

for THIS_DB in `echo $DBs`
do
  DB_VAR=`tnsping $THIS_DB | 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


If you have the DB's stored in a file it's almost the same approach: delete the first two line and replace these 2 with:

for THIS_DB in `cat /path/do/DB's-file`

You probably want 1 mail instead of multiple mails, might want to change that.

Hope this helps.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Simple Scripting Question


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway