Script to list all active databases

The other day I needed a script to list all the active databases on a server.
This is what I came up with :


for dbname in `nawk -F: '{if ($2 !~ /7\.3\.4/ && $1 !~ /^[#*]/ && $3 !~ /N/ ) print $1 }' /var/opt/oracle/oratab`
do
echo $dbname
done

There are three things to note though:

  • The script ignores version 7.3.4 databases
  • It only includes databases that are set to automatically start, i.e. active.
  • It assumes that the oratab file is in /var/opt/oracle
  • Explanation:

    The script parses each line of the oratab file and looks for three things:

    1. That the second column ( $2 ) isn’t 7.3.4, which means the database on the current line is V7
    2. That the first column ( $1 ) isn’t a # or a *, which means the current line is a comment
    3. And that the third column ( $3 ) isn’t an N, which means the database on the current line is set to autostart.

    If all this conditions are met, then the value of the first column ( $1 ) is copied into the variable dbname. Which is then echoed to the screen.

    One thought on “Script to list all active databases

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out /  Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out /  Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out /  Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out /  Change )

    Connecting to %s