|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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? |
|
#2
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Simple Scripting Question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|