Scripts   Home

Find the user on the Baan Application Server from the Informix session on the Database Server

Scripts to find related sessions in the Baan application to the Informix database on different hosts, one the application server, the other the database server, also can be used on the same host.

To use, save the source and cut off the top and bottom to create a unix shar (shell archive) file. Then "sh filename" to create the script files.


### cut here #####
# to unpack, sh this file
echo README.bwho 1>&2
cat > README.bwho <<'End of README.bwho'
Any questions ask sofbot@sofbot.com
http://www.sofbot.com

MANIFEST:

README.bwho
bwho.ksh
bwho_client.ksh
remote_session.ksh

Finds out which processes on the Baan Application server relate to which 
Informix database sessions.  Use with an application server and separate
database server configuration.  Non destructive.

DEPENDENCIES:
rsh, Informix 7.x, tested on Sun 5.5.1, Baan IV

INSTALL:
bwho.ksh and remote_session.ksh are put on the DB server.
bwho_client.ksh is put on the Application server.

USAGE:

$ bwho_client.ksh   --show a list of sessions matching bshells on App server. 
$ bwho.ksh          --show matching bshells on App server on DB server. 
End of README.bwho
echo bwho.ksh 1>&2
cat > bwho.ksh <<'End of bwho.ksh'
#!/bin/ksh
# Install on the Database server.
# Find the user on the AppServer from the Informix user session number
# info on the DbServer.

AWK=nawk; export AWK
APP_HOST=baan_app_host

function getpid {
    PID=$(onstat -g ses $INFORMIXSESSION | $AWK 'NR==6 {print $4}')
    echo $PID
}

function die {
    echo; echo $@; echo
    exit
}

###############################
# Main

    test $# -eq 1 || die "Usage: $0 informix-session"

    export INFORMIXSESSION=$1
    PID=$(getpid)
    LID=$(rsh $APP_HOST ps -f -p $PID | $AWK 'NR==2 {print $1}')
    rsh $APP_HOST ps -fu  $LID 
End of bwho.ksh
echo bwho_client.ksh 1>&2
cat > bwho_client.ksh <<'End of bwho_client.ksh'
#!/bin/ksh
# Install on the Baan Application server.
# Find the corresponding Informix session ID on the DB server.
# List all sessions or just for one PID.
# NOTES: Depends on remote_session.ksh installed on Database server.
#        Depends on rsh.

SCRIPTPATH=/usr/local/bin; export SCRIPTPATH
DBHOST=db_server; export DBHOST
AWK=nawk; export AWK

function list_all {
    for i in  $(ps -ef| grep PIPE | grep -v $$ | $AWK '{print $2}')
    do
        rsh $DBHOST $SCRIPTPATH/remote_session.ksh  | grep $i
    done
}

function die {
    echo; echo $@; echo
    exit
}

###############################
# Main

case $# in
        0 ) list_all;;
        1 ) export PID=$1
            rsh $DBHOST $SCRIPTPATH/remote_session.ksh | grep $PID;;
        * ) die "Usage: $0 [PID]";;
    esac

End of bwho_client.ksh
echo remote_session.ksh 1>&2
cat > remote_session.ksh <<'End of remote_session.ksh'
#!/bin/ksh
# Install on the Database server.

# Used by rsh in bwho_client.ksh on the Baan application server to find the 
# Informix session on the db server.

INFORMIXDIR=/opt/informix
SCRIPTPATH=/user/local/bin; export SCRIPTPATH

. $SCRIPTPATH/informix_prd_env.ksh
$INFORMIXDIR/bin/onstat -g ses
End of remote_session.ksh
### cut here #####