#!/bin/ksh # cpqual - copy a qualifier (or copy unqualified) to a new qualifier # for all filepro files in the current directory # # usage: # cd /u/company/appl/filepro #(defaults to /u/appl/filepro if you don't) # cpqual [empty] # # may be "" in order to create a new qualifier from the unqualified # otherwise, is an existing $PFQUAL (01, az, etc...) # is the new qualifier you want to create # if already exists, you are prompted to "overwrite? y/n" # the optional 3rd parameter "empty", if given, will cause the new # qualifier to have empty key and data (and thus, indexes too) # otherwise key and data are copied whole # # examples: # cpqual "" 01 empty # # makes a new empty qualifier 01 in every file in /u/appl/filepro # # cd /u/united/appl/filepro ; cpqual az gi # # makes a new qualifier gi for every file in /u/united/appl/filepro # # that has an az qualifier now, by copying the az parts # # Notes: # Indexes are rebuilt in the newly created qualifier # but be advised that copying key and data while users might have locks # in them may result in some half-updated records in the new qualifier. # # The old qualifier is never at any risk so it's ok to run while people work # as long as the new qualifier really is new, or at least as long as you # answer "n" to any overwrite warnings. # # If you are copying an existing qualifier, then only files # with the existing qualifier will be copied, but, if you are copying the # unqualified, this will create the new qualifier in every single file # in the current filepro directory. # # brian@aljex.com OLDQ=$1 NEWQ=$2 [ "x$2" = "x" ] && { echo "usage: $0 old new [empty]" ; exit 1 ; } [ "x$1" = "x$2" ] && { echo "Old and New cannot be the same!" ; exit 1 ; } [ "x$3" = "xempty" ] && EMPTY=true || EMPTY=false export OLDQ NEWQ EMPTY # if we are not already in some filepro directory, then cd to /u/appl/filepro pwd |grep -q "/filepro$" || cd /u/appl/filepro echo "working in \c" ; pwd for PFNAME in * ; do # edit the qualify file grep -q "^${NEWQ}$" ${PFNAME}/qualify || echo "$NEWQ" >> ${PFNAME}/qualify # copy key & data for KD in key data ; do ls ${PFNAME}/${KD}${OLDQ}.* >/dev/null 2>&1 && { cp -ip ${PFNAME}/${KD}$OLDQ ${PFNAME}/${KD}$NEWQ && { $EMPTY && >${PFNAME}/${KD}$NEWQ } } done # copy indexes ls ${PFNAME}/index${OLDQ}.* >/dev/null 2>&1 && { for IXFILE in ${PFNAME}/index${OLDQ}.* ; do IX=`echo $IXFILE |sed "s;${PFNAME}/index${OLDQ}\.;;"` cp -ip $IXFILE ${PFNAME}/index${NEWQ}.$IX done PFQUAL=$NEWQ dxmaint $PFNAME -ra -e } done