Unix Code - Detail View


Date

Name

Plattform

Language

Kurzbeschreibung

Owner

Link

19.10.2001

list_proc.ksh

Unix

Shell

Printing Application  and Process Information

IBM Corp. 2000

ftp://www.redbooks.ibm.com/redbooks/sg246012

DB2 ist ein Produkt der
IBM Corporation. Bitte
Copyright-  und Trademark-Hinweise beachten!

#!/bin/ksh

echo "SYNTAX: `basename $0` [Application Handle]"

APPS=${1:+"APPLICATION AGENTID $1"}  # Optional AGENTID parameter
APPS=${APPS:-"ALL APPLICATIONS"}     # Default is all Applications

echo ""
echo "Printing Application/Proccess Info for $APPS"
echo ""
echo "db2 get snapshot for $APPS"

db2 get snapshot for $APPS | awk -F= '

BEGIN{    SNAP_TIME_FLAG="" }

/Not Collected/{ next      }
/Application handle/{ APP_HANDLE= "" ;
  APP_NAME= "" ;
  APP_ID= "" ;
  CON_TIME= "" ;
  USER_ID= "" ;
  LOGIN_ID= "" ;
  NNAME= "" ;
  APP_PROC= "" ;
  CLIENT_TYPE= "" ;
  ADDRESS= "" ;
  DB_NAME= "" ;
  SNAP_TIME= "" ;
  AGENT_PROC= "" ;
##############################
# With all Snapshots turned ON
  APP_STATUS= "" ;
  APP_IDLE= "" ;
  UOW_PREV_TS= "" ;
  UOW_PREV_T= "" ;
  UOW_START_TS= "" ;
  UOW_STATUS= "" ;
  UOW_PREV_OP= "" ;
}
/Application handle/{ APP_HANDLE= $2 }
/Application name/{ APP_NAME= $2 }
/Application ID/{ APP_ID= $2 }
/Connection request start timestamp/{ CON_TIME= $2 }
/Authorization ID/{ USER_ID= $2 }
/Client login ID/{ LOGIN_ID= $2 }
/Configuration NNAME of client/{ NNAME= $2 }
/Process ID of client application/{ APP_PROC= $2 }
/Communication protocol of client/{ CLIENT_TYPE= $2 }
/Inbound communication address/{ ADDRESS= $2 }
/Database name/{ DB_NAME= $2 }
/Snapshot timestamp/{ SNAP_TIME= $2 }
/Coordinator agent process or thread ID/{ AGENT_PROC= $2 }
##############################
# With all Snapshots turned ON
/Application status/{ APP_STATUS= $2 }
/Application idle time/{ APP_IDLE= $2 }
/Previous UOW completion timestamp/{ UOW_PREV_TS   = substr($2,12)}
/Elapsed time of last completed uow \(sec.ms\)/{ UOW_PREV_T= $2 }
/UOW start timestamp/{ UOW_START_TS  = substr($2,12)}
/UOW completion status/{ UOW_STATUS= $2 }
/Most recent operation   /{ UOW_PREV_OP= $2 }

# Last line of application data
/  Agent process\/thread ID/{

   if ( SNAP_TIME_FLAG == "" )
   {
   SNAP_TIME_FLAG="1";
   print "Snapshot Time:", SNAP_TIME;
   print "";
   print "HANDLE        APPLICATION-ID        CONNECT-TIME"
   print "CLIENT-USER  DB-USER      DATABASE  CONNECT-TYPE"
print "STATUS         RECENT-OP       LAST-UOW"
print "UOW-START      PREV-UOW-START  UOW-STATUS"
   print "=============================================================";
   }
   print "";
   print "=============================================================";
   printf "%3.3s %30.30s %26.26s\n",
   APP_HANDLE,
   APP_ID,
   CON_TIME;
   printf "%10.10s %10.10s %10.10s   %s\n",
   LOGIN_ID,
   USER_ID,
   DB_NAME,
   CLIENT_TYPE;
   printf "%-15.15s %-15.15s %8.8s\n",
APP_STATUS,
UOW_PREV_OP,
UOW_PREV_T;
   printf "%-15.15s %15.15s %s\n",
UOW_START_TS,
UOW_PREV_TS,
UOW_STATUS;

   print "-------------------------------------------------------------";
   if ( APP_NAME ~ /db2bp/ && CLIENT_TYPE ~ /Local/ )
   {
   PS="";
   while ( "ps -fp" APP_PROC | getline PS) {};
   if ( PS ~ APP_PROC ) {
   n=split( PS, psline, " ");
   CLIENT_PROC=psline[n-1];

   PS="";
   while ( "ps -fp" CLIENT_PROC " 2>/dev/null" | getline PS );
   if ( PS ~ CLIENT_PROC ) print PS;
   }
   }

   if ( CLIENT_TYPE !~ /Local/ )
   {
   print "REMOTE CLIENT (" CLIENT_TYPE ") FROM " ADDRESS " (" NNAME \
      ") USING PROCESS " APP_PROC;
   }

   PS="";
   while ( "ps -fp" APP_PROC " 2>/dev/null" | getline PS ) {};
   if ( PS ~ APP_PROC ) print PS;

   PS="";
   while ( "ps -fp" AGENT_PROC " 2>/dev/null" | getline PS ) {};
   if ( PS ~ AGENT_PROC ) print PS;
}
'

exit

© Gernot Ruban