#!/bin/ksh # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # 61haes_r714 src/43haes/usr/sbin/cluster/diag/cld_trace.sh 1.6 # # Licensed Materials - Property of IBM # # COPYRIGHT International Business Machines Corp. 1990,1998 # All Rights Reserved # # US Government Users Restricted Rights - Use, duplication or # disclosure restricted by GSA ADP Schedule Contract with IBM Corp. # # IBM_PROLOG_END_TAG # @(#)72 1.6 src/43haes/usr/sbin/cluster/diag/cld_trace.sh, hacmp.diags, 61haes_r714 7/20/98 15:48:59 # $Id: cld_trace.sh,v 4.3 1996/07/15 21:33:38 bobbyg Exp $ # # COMPONENT_NAME: DIAG # # FUNCTIONS: trace_report # traceoff_daemons # usage_message # # ORIGINS: 27 # # # (C) COPYRIGHT International Business Machines Corp. 1990,1994 # All Rights Reserved # US Government Users Restricted Rights - Use, duplication or # disclosure restricted by GSA ADP Schedule Contract with IBM Corp. # # ######################################################################## # Function GET_TRACEIDS # This function is called from function "traceon_daemons" and # checks to see if the entered daemons are valid. # * If they are then it returns their trace ids and the value 0. # * If they aren't, then it returns value 1. # ######################################################################## get_traceids () { HASERROR=0 for DAEMON in $@ # # do the following while there are any daemons # do case $DAEMON in clstrmgr ) echo 910 ;; clinfo ) echo 911 ;; cllockd ) echo 912 ;; clsmuxpd ) echo 913 ;; * ) HASERROR=1 ;; esac done return $HASERROR } ###################################################################### # Function TRACEON_DAEMONS # This function called by the main routine takes as arguments the # list of daemons entered by the user. If no daemons are entered, an # error message is displayed. Otherwise, the function gets the # process ids and initiates the tracing process for each daemon, # depending on whether a long trace or a short trace was requested # (specified in the variable $LONG). ##################################################################### traceon_daemons () { if [ $# = 0 ] then usage_message # Display message if no daemons entered. exit 1 else PCOUNT=0 for DAEMON in $@ do # get Process ids. # TEST=`lssrc -s $DAEMON` if [ $? -ne 0 ] then PID="" else PID=`lssrc -s $DAEMON | awk '{print $3}' | sed -e 's/[^0-9]//g'` fi if [ -z "$PID" ] then /bin/dspmsg scripts.cat 558 "ERROR: Daemon not running.\n" >&2 # Remove the "exit 1" code. Otherwise, if the error daemon occurs after # the first element of the list, some daemon will has traceson and never # get turned off. # If the daemon has no process # id, an error message is else # displayed. if [ $DAEMON != cllockd ] # cllockd in kernel so trace then # doesn't have to be enabled traceson -p $PID $LONG fi PCOUNT=`expr $PCOUNT + 1` fi done if [ $PCOUNT -eq 0 ] then exit 1 fi TRACE_IDS=`get_traceids $@` # stores the trace ids in TRACE_IDS # # The function will use the trace ids obtained from "get_traceids" # to start the trace. If any daemon not valid is entered, an error # message will be displayed. # if [ $? -ne 0 ] then /bin/dspmsg scripts.cat 559 "ERROR: daemon not valid\n" >&2 /bin/dspmsg scripts.cat 560 "Valid daemons are: clstrmgr, clinfo, cllockd, clsmuxpd.\n" >&2 fi # # Starting the trace for all daemons # Data is stored in the file 'cltrace.$$' # /usr/lib/ras/trace_smutil trace -j "$TRACE_IDS" -o /usr/adm/ras/cltrace.$$ -a fi } ###################################################################### # Function TRACEOFF_DAEMONS # This function called from the main routine, first stops the trace. # After tracing is stopped, it turns the tracing off on each daemon # according to their process ids. ##################################################################### traceoff_daemons () { trcstop # stop the trace for DAEMON in $@ do TEST=`lssrc -s $DAEMON` if [ $? -ne 0 ] then PID="" else PID=`lssrc -s $DAEMON | awk '{print $3}' | sed -e 's/[^0-9]//g'` fi if [ -z "$PID" ] then /bin/dspmsg scripts.cat 561 "ERROR: Daemon not running.\n" >&2 else if [ $DAEMON != cllockd ] # cllockd in kernel so trace then # doesn't have to be disabled tracesoff -p $PID fi fi done } ################################################################## # Function TRACE_REPORT # This function generates a trace report. If a file is entered # the report is sent to that file. Otherwise, the report is # sent to standard output. ################################################################## trace_report () { # # Before it starts the report, it checks if the raw # data file exists (cltrace.$$). trap 'exit 1' 1 2 3 # To exit from the trace report to # the command line. if [ ! -f /usr/adm/ras/cltrace.$$ ] then exit 1 else if [ -z "$FILE" ] then trcrpt -O exec=y -O pid=y -O svc=y -O timestamp=1 -d "$TRACE_IDS" /usr/adm/ras/cltrace.$$ | more else trcrpt -O exec=y -O pid=y -O svc=y -O timestamp=1 -d "$TRACE_IDS" /usr/adm/ras/cltrace.$$ > $FILE fi fi # # After it generates the report, it removes the raw data file. rm -f /usr/adm/ras/cltrace.$$ } ################################################################# # Function USAGE_MESSAGE # This function displays an error message on the screen every # time a usage error occurs. ################################################################# usage_message () { /bin/dspmsg scripts.cat 563 "Usage: trace [-t time] [-R file] [-l] daemon ...\n" >&2 /bin/dspmsg scripts.cat 600 "Where: \n" >&2 /bin/dspmsg scripts.cat 601 " -t time is the number of seconds to perform the trace\n" >&2 /bin/dspmsg scripts.cat 602 " -R file is the file to which output is saved\n" >&2 /bin/dspmsg scripts.cat 603 " -l chooses a more detailed trace option\n" >&2 /bin/dspmsg scripts.cat 604 " daemon is a list of cluster daemons to trace\n" >&2 } ################################################################# # MAIN ROUTINE # This main routine receives all the arguments entered by the # user. It checks to see if the conditional flags are valid # and assigns their value to their respective variables. # The other sub-routines are then called and the daemon names # entered are passed to them, depending whether they are # necessary or not. ################################################################## set -- `getopt t:R:l $*` if [ $? -ne 0 ] then # If an invalid flag is entered, usage_message # an error message is displayed. exit 1 else FILE="" LONG="" # Initially a short trace is executed, SLEEP_VAR=30 # during 30 seconds while [ $1 != -- ] do case $1 in # The case statement gets the values of # SLEEP_VAR, FILE, and LONG, if entered # by the user. -t ) SLEEP_VAR=$2 shift 2 ;; -R ) FILE=$2 shift 2 ;; -l ) LONG="-l" shift ;; esac done fi shift # loose -- # # This "trap" command will stop the trace and generate # the report whenever the user wants to by pressing ^c. # trap '/bin/dspmsg scripts.cat 564 "Trace interrupted\n" >&2; traceoff_daemons $@; trace_report; rm -f /usr/adm/ras/cltrace.$$; exit 1' 1 2 3 traceon_daemons $@ # call to function traceon_daemons. sleep $SLEEP_VAR # After tracing is initiated the program goes to sleep # for the amount of time specified by the variable # SLEEP_VAR. After this, traceoff_daemons $@ # call to function traceoff_daemons. trace_report # call to function trace_report.