[ Informix Logo ] Архив интересных статей по Informix
Пред. по дате ] [ След. по дате ] [ Пред. по нити ] [ След. по нити ][ Индекс по датам ][ Индекс по нитям ]

How to know the number of Informix Instances

From "Shulzhenko Vasyl" <vasilis@softline.kiev.ua>
Date Tue, 9 Mar 1999 17:10:54 +0200


>Hi Family,
>
>I have a script to show running Informix instances on my machine
>and today I rewrote it to be more general. I don't know how
>successful I was in that intention, but here it is.
>
>First some background information:
>
>Basic idea is to use the 'e' flag of BSD style 'ps' command which
>display environment variables for the running processes.
>After identifying initial shared memory segments for every Informix
>instance with ipcs, we can derive server number and PID of master
>oninit/tbinit processes. Using this PID we can catch the whole
>environment for master oninit/tbinit processes with command 'ps ew'.
>The 'w' flag provides enough room to show environment variables.
>If your environment is too big, you can play with multiplying
>the 'w' flag, like 'ps eww' or 'ps ewww'.
>Because all Informix OnLine/IDS engines v 5.x, 6.x and 7.x needs
>at least two variables INFORMIXDIR and ONCONFIG, I think that we
>have enough information for running servers. I don't know when were
>introduced INFORMIXSERVER and INFORMIXSQLHOSTS variables, but if we
>can't find them in environment, my assumption is that INFORMIXSERVER
>can be found in displayed ONCONFIG file and INFORMIXSQLHOSTS defaults
>to $INFORMIXDIR/etc/sqlhosts.
>At the end, we can run onstat/tbstat for found instances and show
>version and type of the engine.
>
>The script is called ixservers and produces report similar to
>the one produced with 'onstat -g dis' command. It can be run by
>every user, not only root or informix.
>
>On my machine it display the following information:
>
>mladen@MinFin:/usr/users/mladen
>> ixservers
>
>Server Number : 0
>Server        : minfin
>INFORMIXDIR   : /usr/informix
>ONCONFIG      : onconfig.minfin
>SQLHOSTS      : INFORMIXSQLHOSTS is not set
>
>INFORMIX-OnLine Version 7.24.FC5   -- On-Line -- Up 3 days 10:52:12 --
>51544 Kbytes
>
>
>Server Number : 14
>Server        : ifmx_online
>INFORMIXDIR   : /mvr/informix
>ONCONFIG      : onconfig.ifmx
>SQLHOSTS      : /mvr/informix/etc/sqlhosts.ifmx
>
>INFORMIX-OnLine Version 7.12.UC1   -- On-Line -- Up 3 days 11:58:39 --
>9248 Kbytes
>
>
>There are 2 servers running on host MinFin
>
>Warnings and disclaimer:
>
>To run this script you need a BSD style version of the 'ps' command.
>On some Unix systems it can be found in /usr/ucb directory.
>If you don't have such a version of the 'ps', you may try to get and
>tweak the 'sps' utility (Show Process Status) written by J. Robert Ward
>for SunOS and Ultrix. It is somewhere on the net, but unfortunately
>I have no time to play with it.
>
>This script is tested only on Digital Unix v 4.0b and 4.0d.
>I have no access to older Informix engines ( 5.x and 6.x) to test it,
>but I hope it should work. I have only one 7.12 version and it works
>for me.
>
>Digital Unix version of the 'ipcs' command displays the KEY field as
>decimal and I had to play with conversion decimal<->hex. But I have
>tested this portion of code with SCO OSR 5.04 which displays hex and
>it works.
>
>You should pay attention on the number of fields reported by your
>version of the 'ipcs -am' command and identify which field is PID
>for the master oninit/tbinit process. On Digital Unix this is field
>number 11, but on SCO this is field number 10 and those values are
>coded in the script.
>
>Last statement:
>
>I know that this piece of code is ugly, but it works for me !
>If you find it useful, maybe someone could rewrite it with more
>style and to be more general. In such a case maybe it can be
>uploaded to the IIUG software repository.
>Personally, my favorite writer of good, clean, well designed
>and optimized code is Jonathan Leffler.
>
>Best regards and sorry for long posting
>
>Mladen
>
>-- 
>----------------------------------------------------------------------
> Mladen Jovanovski                E-mail:          mladen@ultra.com.mk
> ULTRA Computing, Ltd.            Phone/Fax:          +389 91 36 26 36
> Partizanski odredi 70b                       
> P.O.Box 798                              
> 91000 Skopje
> Macedonia, Europe
>----------------------------------------------------------------------
>
>--------------------- Cut here ---------------------------------------
>#!/bin/sh
>
>################################################################################
>#
># Program : ixservers.sh
>#
># Author : Mladen Jovanovski (mladen@ultra.com.mk)
>#
># Version : 1.0
>#
># Date : 04-02-1999.
>#
># Description : This is a script for identifying Informix instances
>#   running on a single host machine
>#
># Disclaimer : The author claim no responsibility for any
>#   misuse of this script directly or indirectly.
>#   There is no official support for this utility
>#   from Informix or any other company.
>#   This script is tested only on Digital UNIX
>#   v 4.0b and 4.0d
>#
># Comments : Any improvements, suggestions, comments are welcome
>#   and can be directly mailed to the author.
>#   Hope you find this useful. Good luck!
>#
>################################################################################
>
>OSTYPE="BSD" # Needed for conversion from decimal to hex
> # if your ipcs display KEY value as decimal
>#OSTYPE="" # For System V change to this
>
>PS=/usr/bin/ps # BSD style ps command
> # on some System V machines it can be found
> # as /usr/ucb/ps
>
>HOST=/usr/bin/hostname # Your command of choice to display
> # short hostname ( like uname -n )
>
>IFXSEG1="" # Initial (first) shared memory segment for every
> # Informix instance, hex KEY value from ipcs
> # ( hex like 0x52564801 )
>
>KEYFIRST="" # First part of the hex KEY value from ipcs
> # ( hex 0x5256 + DBSERVERNUM ), but decimal
>
>KEYLAST="4801" # Last part of the hex KEY value from ipcs
> # ( hex 0x4801 )
>
>KEYZERO=21078 # First part of the hex KEY value from ipcs
> # for DBSERVERNUM 0, but decimal (hex 0x5256)
>
>MPID="" # Process ID for the master oninit/tbinit process
>
>TOTAL=0 # Total number of runing servers
>
>get_first_seg(){
>
> if [ "$OSTYPE" = "BSD" ]
> then
> ipcs -m | \
> grep informix | \
> echo "obase=16\n`awk '{print $3}'`" | \
> bc | \
> grep 4801
> else
> ipcs -m | \
> grep informix | \
> awk '{print $3}' | \
> grep 4801 | \
> sed 's/0x//'
> fi
>
>}
>
>get_mpid(){
>
> if [ "$OSTYPE" = "BSD" ]
> then
> IFXSEG1L=`echo "ibase=16\n\`echo $IFXSEG1\`" | bc`
> ipcs -am | grep $IFXSEG1L | awk '{print $11}'
> else
> ipcs -am | grep $IFXSEG1 | awk '{print $10}'
> fi
>
>}
>
>get_env_var(){
>
> VARSETTING=`$PS ew -p $MPID | \
>     tail -1 | \
>     sed 's/^.*'"$1"'\=/'"$1"'\=/; s/ .*//'`
> VAREXIST=`echo $VARSETTING | grep -c "$1\="`
> if [ "$VAREXIST" = 1 ]
> then
> echo $VARSETTING | sed 's/^.*'"$1"'\=//'
> else
> echo "$1 is not set"
> fi
>
>}
>
>set_onstat(){
>
> ONINIT=`$PS -o comm= -p $MPID`
>
> if [ "$ONINIT" = "oninit" ]
> then
> echo "onstat -"
> else
> echo "tbstat -"
> fi
>
>}
>
>for IFXSEG1 in `get_first_seg`
>
>do
>
> KEYFIRST=`echo "ibase=16\n\`echo $IFXSEG1 | \
> sed 's/'$KEYLAST'//'\`" | \
> bc`
>
> DBSERVERNUM=`expr $KEYFIRST - $KEYZERO`
>
> MPID=`get_mpid`
>
> INFORMIXSERVER=`get_env_var INFORMIXSERVER`
> INFORMIXDIR=`get_env_var INFORMIXDIR`
> ONCONFIG=`get_env_var ONCONFIG`
> INFORMIXSQLHOSTS=`get_env_var INFORMIXSQLHOSTS`
> PATH=$INFORMIXDIR/bin:$PATH
> export INFORMIXSERVER INFORMIXDIR ONCONFIG PATH
>
> echo ""
> echo "Server Number : $DBSERVERNUM"
> echo "Server        : $INFORMIXSERVER"
> echo "INFORMIXDIR   : $INFORMIXDIR"
> echo "ONCONFIG      : $ONCONFIG"
> echo "SQLHOSTS      : $INFORMIXSQLHOSTS"
>
> ONSTAT=`set_onstat`
> $ONSTAT
>
> TOTAL=`expr $TOTAL + 1`
>
>done
>
>echo "
>There are $TOTAL servers running on host `$HOST`"
>
>---------------------- Cut here -----------------------------------


Home ] Сайт создан при поддержке Украинского представительства Informix Software Inc. Hosted by ANTEC