showlock command
Bob Stockler
bob at trebor.iglou.com
Wed Apr 25 15:00:28 PDT 2007
Top Post . . .
As an AIX compiled "showlock" program is required, so also is the
KornShell required to run the shell script "lock.info", and I'm not
sure it's distributed with AIX (though the script could possibly be
edited to run under another shell).
Bob
John Esak wrote (on Wed, Apr 25, 2007 at 05:31:14PM -0400):
| showlock is a small C program. You would have to get the version compiled
| for your AIX system. I'm sure Ken could send it to you. A compiled version
| that is. However, once you get that... be sure to use it with "lock.info"
| which I'll include below. It makes better use of the showlock output.
|
| John
|
| Here is lock.info put it in a script by itself and run it once you get
| showlock. Put them both in a PATH directory like /usr/local /bin/ (whatever
| that might be on AIX).
|
| (It's a long script, be sure to get it all into a file, make it executable
| and call it "lock.info".
|
|
| #!/bin/ksh
| # @(#) lock.info - v00.00.05 - report info re filePro file locks
| PROG=${0##*/} ; v=v00.00.05
| Usage="
| Reports information on filePro file locks ($v).
|
| Syntax: $PROG [ [-d] [-p] [-m qualifier] filename [...] ]
|
| -d - Print the date & time on each execution
| -p - Prompt the user between each lock report
|
| Executed with filePro file names as arguments it reports
| the file name, locked record number, user name, tty and
| command being executed for all locks on all target files.
|
| Executed without file name arguments it prompts for file
| names. Entering a blank line at this prompt causes the
| present working directory to become the target file.
|
| PFPROG, PFDATA, PFDIR, PFQUAL and PFDSK (or FP analogs,
| preferring PF identifiers) set in the environment are
| recognized and observed.
|
| Requires the compiled executable program 'showlock'.
| "
| while getopts m:dp flag 2>/dev/null
| do case $flag in
| d) DATE=1 ;;
| m) PFQUAL=$OPTARG ;;
| p) PROMPT=1 ;;
| \?) print -u2 "$Usage" ; exit 2 ;;
| esac
| done
| shift $(( $OPTIND - 1 ))
|
| : ${PFPROG:=$FPPROG} ${PFDATA:=$FPDATA} ${PFDIR:=$FPDIR} ${PFQUAL:=$FPQUAL}
| # See if any of PFPROG, PFDATA, & PFDIR are not in the environment;
| # prefer PFPROG, PFDATA & PFDIR, but accept FPPROG, FPDATA or FPDIR.
| # If any are missing, read /etc/default/fppath putting defaults for
| # PFPROG, PFDATA & PFDIR in the array elements FP[1], FP[2] & FP[2]:
| [[ -z $PFPROG || ( -z $PFDATA || -z $PFDIR ) ]] && {
| [[ -r /etc/default/fppath ]] && { typeset -i i=0
| while read ; do FP[((i+=1))]=$REPLY ; done </etc/default/fppath
| } || {
| print -u2 "\n $PROG: Can't read \"/etc/default/fppath\".\n" ; exit 2
| }
| }
| # See if the filePro programs directory can be found:
| [[ -d ${PFPROG:=${FP[1]}}/fp ]] || {
| print -u2 "\n $PROG: Can't find the filePro Programs.\n" ; exit 2
| }
| # Assure the script is being run with "root" or "filepro" permissions:
| [[ -w $PFPROG/fp/lib/errmsg ]] || {
| print -u2 "\n $PROG: Must be run by \"root\" or \"filepro\".\n" ; exit 2
| }
|
| # See if the filePro files directory can be found:
| [[ -d ${PFDATA:=${FP[2]}}${PFDIR:=${FP[3]}}/filepro ]] || {
| print -u2 "\n $PROG: Can't find the filePro Files.\n" ; exit 2
| }
| [[ -n ${PFDSK:=$FPDSK} ]] && {
| ifs=$IFS ; IFS=: ; set -A FS " " $PFDSK ; IFS=$ifs ;}
|
| # Get the full pathname for 'ps':
| PS=$(whence ps)
| [[ -z $PS ]] && {
| print -u2 "\n $PROG: Can't find the 'ps' command.\n" ; exit 2
| }
|
| # See if the filePro files directory can be found:
| [[ -d ${PFDATA:=${FP[2]}}${PFDIR:=${FP[3]}}/filepro ]] || {
| print -u2 "\n $PROG: Can't find the filePro Files.\n" ; exit 2
| }
| [[ -n ${PFDSK:=$FPDSK} ]] && {
| ifs=$IFS ; IFS=: ; set -A FS " " $PFDSK ; IFS=$ifs ;}
|
| # Get the full pathname for 'ps':
| PS=$(whence ps)
| [[ -z $PS ]] && {
| print -u2 "\n $PROG: Can't find the 'ps' command.\n" ; exit 2
| }
|
| # Get the full pathname for 'showlock':
| : ${SHOWLOCK:=$(whence showlock)}
| [[ -z $SHOWLOCK ]] && {
| print -u2 "\n $PROG: Can't find the 'showlock' command.\n" ; exit 2
| }
|
| # Use the fastest AWK on the system:
| : ${AWK:=$(whence mawk)} ${AWK:=$(whence gawk)} ${AWK:=$(whence awk)}
| [[ -z $AWK ]] && {
| print -u2 "\n $PROG: Can't find the 'awk' command.\n" ; exit 2
| }
|
| (( $# > 0 )) && FILES=$@ || {
| # If no file names were entered, get them now:
| print -n "
| Enter one or more filePro file names (each separated by a space)
| on the next line, and then press [ENTER]:
| " ; read FILES
| # A blank line defaults to be the present directory:
| [[ -z $FILES ]] && FILES=${PWD##*/}
| }
|
| typeset -i dec_offset="10#" Key_Record_Length i j
|
| [[ $PROMPT = 1 ]] && clear
| [[ $DATE = 1 ]] && { print "" ; /bin/date ;}
| for PFNAME in $FILES
| do # Assure it's a filePro file:
| #[[ -r $PFDATA$PFDIR/filepro/$PFNAME/map ]] || {
| #print "\n $PROG: \"$PFNAME\" is NOT a filePro File."
| #[[ $PROMPT = 1 ]] && {
| [[ $PROMPT = 1 ]] && clear
| [[ $DATE = 1 ]] && { print "" ; /bin/date ;}
| for PFNAME in $FILES
| do # Assure it's a filePro file:
| #[[ -r $PFDATA$PFDIR/filepro/$PFNAME/map ]] || {
| #print "\n $PROG: \"$PFNAME\" is NOT a filePro File."
| #[[ $PROMPT = 1 ]] && {
| #print -nu2 "\n Press [ENTER] to continue: " ; read akey
| #}
| #continue
| #}
|
|
| # Assure the key file can be read:
| [[ -r $PFDATA$PFDIR/filepro/$PFNAME/key$PFQUAL ]] && {
| PFdata=$PFDATA
| } || {
| PFdata=""
| [[ -n $PFDSK ]] && {
| for DIR in ${FS[@]}
| do [[ -r $DIR/$PFDIR/filepro/$PFNAME/key$PFQUAL ]] && {
| PFdata=$DIR ; break ;}
| done
| }
| [[ -z $PFdata ]] && {
| print "\n $PROG: Can't read the \"$PFNAME\" key$PFQUAL file."
| [[ $PROMPT = 1 ]] && {
| print -nu2 "\n Press [ENTER] to continue: " ; read akey
| }
| continue
| }
| }
| # Read the map file to get the filePro key record length:
| read map < $PFDATA$PFDIR/filepro/$PFNAME/map ; map=${map#*:}
| Key_Record_Length=${map%%:*}
|
| # Get the output of 'showlock' into an array:
| set -A SL_OUT $( $SHOWLOCK $PFdata/$PFDIR/filepro/$PFNAME/key$PFQUAL )
| (( ${#SL_OUT[@]} == 1 )) && {
| print "\n There are NO locks on the \"$PFNAME\" key$PFQUAL file."
| [[ $PROMPT = 1 ]] && {
| print -nu2 "\n Press [ENTER] to continue: " ; read akey
| }
| continue
| }
| i=1 ; j=1 ; I=""
| while (( j < ${#SL_OUT[@]} ))
| do hex_offset=${SL_OUT[j]} # hex offset of the lock into the file
| dec_offset="16#$hex_offset" # decimal offset of the lock into the
| file
| (( j += 2 ))
| PID[i]=${SL_OUT[j]} # the PID of the process holding the lock
| # Get the record number of the lock:
| REC_NUM[i]=$(( ( dec_offset - 16 ) / ( Key_Record_Length + 20 ) ))
| (( j += 1 )) ; I="$I $i" ; (( i += 1 ))
| done
| for i in $I
| do # Get user name, tty & command for the process holding the lock:
| eval $( $PS -ef |
| $AWK -v PID="${PID[i]}" '
| $2 == PID { print "USER=" $1 ; print "TTY=" $6
| $1 = $2 = $3 = $4 = $5 = $6 = $7 = ""
| sub(/^[ \t]+/,"")
| print "CMD=\"" $0 "\"" }' )
| # Display the results:
| print "
| filePro File: $PFNAME
| Record Number: ${REC_NUM[i]}
| User: $USER
| TTY: $TTY
| Command: ${PID[i]}
| $CMD"
| [[ $PROMPT = 1 ]] && {
| print -nu2 "\n Press [ENTER] to continue: " ; read akey
| }
| done
| done
|
| exit 0
|
| # EOF 'lock.info' - Bob Stockler - Thu Jun 4 14:14:14 EDT 1998
|
|
|
| _______________________________________________
| Filepro-list mailing list
| Filepro-list at lists.celestial.com
| http://mailman.celestial.com/mailman/listinfo/filepro-list
--
Bob Stockler +-+ bob at trebor.iglou.com +-+ http://members.iglou.com/trebor
More information about the Filepro-list
mailing list