03 March 2010

Columns showing active databases

When I logon to a server with a large number of databases on it, I like to see what instances are active. When the list is growing, a simple grep on e.g. pmon processes would not give a nice list. Columns can be created with the pr command:

ls /usr/bin | pr -T4 -W$

The screenwidth in a script can be found with the $(tput cols) variable or - outside a script - with the $COLUMNS variable. Putting it all together gives me the following, which can be sourced in .bash_profile if you like. Nice thing is, that the number of columns is variable and will change depending on your screenwidth.

# Determine number of columns to use
MINCOLWD=10 # minimum column width
SCRNCHAR=$(( $(tput cols) )) # screen width
NROFCOLS=$(( $SCRNCHAR / $MINCOLWD )) # number of columns


ps -ef | grep pmon | grep -v 'grep pmon' | awk '{ print substr($8,10,10) }' | sort | pr -T${NROFCOLS} -W${SCRNCHAR} > list_db.tmp
cat list_db.tmp
#
# Determine number of active databases
NRACTDB=`ps -ef | grep pmon | grep -v 'grep pmon' | wc -l`
echo \>\> Total: $NRACTDB databases active


The output looks like this:

ABCONT61  COVUG02   DPSONT   ESYUNTD1  LNXBTR01
ABCONT62  CRILS30T  DPSTST   GFKONT    LNXTTO 
BRFP01    CRILS61   ECWCTST  HBJSONT   OAADB  
BKDWHO    CRILS61T  ECWPTST  INOKDS01  SQWWUR 
BKDWHT    CRILS62
>> Total: 26 databases active