#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    1
    Rep 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 blah@blah.com
    fi

    How can I do this with a number of different database names?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    137
    Rep 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.

IMN logo majestic logo threadwatch logo seochat tools logo