Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2004
    Posts
    5

    Unanswered: 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?

  2. #2
    Join Date
    Jan 2004
    Posts
    51

    Re: shell scripting question

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •