Function List incomplete
-
Greetings. I recently noticed that the Function List for some of my Shell-formatted scripts is incomplete. I write my scripts using a fairly consistent format when it comes to my functions. For some reason, this function refuses to show up in the list even after saving, closing NPP and restarting. I have several other functions that all show up in the list. I didn’t find any previous posts that were related to Shell-formatted functions, and I didn’t see anything in the bash.xml function list template that looked like it might cause it to be excluded. Any help is appreciated. Debug info included below the function code.
Thanks!
fix_install() { print_msg "(${MM}/${DD} $(date +%R)) Started fix_install" "debug" unset FIXFILE FIXRPMSBASE FIXRPMSFP FIXSVR MQFIXCMD MQFIXCMDOUT local FIXFILE="${MQINSTBASE}${MQVERSION}.tar.gz" local FIXRPMSBASE="$( echo -e "${_MQRPMS}" | grep -ivE "(BES|${MQVERBASEERE}[^0])" | tr -s '\n' ' ' )" local FIXRPMSFP="$( echo -e "${_MQRPMS}" | grep -ivE "(BES|${MQVERBASEERE}0)" | tr -s '\n' ' ' )" local FIXSVR="${1}" local MQFIXCMD="" local let MQFIXCMDOUT=99 MQFIXCMD="${RPMINST} --force ${FIXRPMSFP} 2>&1 ; echo -e \"RESULT=\$?\"" print_msg "FIXFILE=${FIXFILE}~n\nFIXRPMSBASE=${FIXRPMSBASE}~n\nFIXRPMSFP=${FIXRPMSFP}\ ~nFIXSVR=${FIXSVR}~n\nMQFIXCMD=${MQFIXCMD}~nMQFIXCOUNT=${MQFIXCOUNT}" "debug" if (( DRYRUN )) then print_msg "copy_files ${FIXSVR} ${SOURCESVR} \"${(e)SOURCEDIR}${PATCHVER}\" \"${FIXFILE}\"" "dryrun" print_msg "MQFIXCMDOUT=\"\$( nexec -i -l \${FIXSVR} \"\${MQFIXCMD}\" )\"" "dryrun" else copy_files ${FIXSVR} ${SOURCESVR} "${(e)SOURCEDIR}${PATCHVER}" "${FIXFILE}" MQFIXCMDOUT="$( nexec -i -l ${FIXSVR} "${MQFIXCMD}" )" if [[ $( echo -e "${MQFIXCMDOUT}" | grep -i "RESULT=" | cut -f2 -d'=' ) != 0 ]] then ERRORDESC="ERROR 12 : Errors detected after fixing install on ${FIXSVR}" let ERROR_CODE=12 critical_error fi fi print_msg "(${MM}/${DD} $(date +%R)) End fix_install" "debug" }
Debug Info
Notepad++ v8.5.3 (64-bit)
Build time : May 15 2023 - 06:09:36
Path : C:\Program Files\Notepad++\notepad++.exe
Command Line :
Admin mode : OFF
Local Conf mode : OFF
Cloud Config : OFF
OS Name : Windows 10 Enterprise (64-bit)
OS Version : 22H2
OS Build : 19045.2965
Current ANSI codepage : 1252
Plugins :
BetterMultiSelection (1.5)
BigFiles (0.1.3)
CodeAlignmentNpp (14.1.107)
Comment Wrap (1.0.0.5)
ComparePlugin (2.0.2)
ComparePlus (1.1)
DSpellCheck (1.5)
GitSCM (1.4.8.2)
HTMLTag (1.3.7)
JSMinNPP (1.2205)
JsonTools (4.14)
Linter (0.1)
mimeTools (2.9)
nppConverter (4.5)
nppcrypt (1.0.1.6)
NppExport (0.4)
NppGist (1.5.1.35)
NPPJSONViewer (2.0.5)
nppplugin_svn (3.0.1)
NppQrCode64 (0.0.0.1)
NppSaveAsAdmin (1.0.211)
NppSnippets (1.7.1)
NppToolBucket (1.10.6622.41516)
NppXmlTreeviewPlugin (2)
Python Indent (1.0.0.4)
PythonScript (2)
RegexTrainer (1)
Remove Duplicate Lines (1.3)
RestApiToText (1.4.0.1)
SelectToClipboard (1.0.3)
SQLinFormNpp64 (6.23.3.24)
urlPlugin (1.2)
XMLTools (3.1.1.13)
_CustomizeToolbar (5.3) -
@greg-michael said in Function List incomplete:
For some reason, this function refuses to show up in the list
I suspect it’s not this function, but rather what else is in your script that is causing the issue:
comments, newlines, mismatched braces … ?
Cheers.
-
@Michael-Vincent When I run the script, there are no errors regarding mismatched/unmatched parentheses, braces, brackets, etc. It also makes me wonder why the other functions would show up in my functions list, but not this one. I’ll see about yanking the whole thing out, saving it, closing NPP, and then adding it back in. Might be some trial and error, but maybe there’s something there that shouldn’t be that I just am not seeing.
-
@Michael-Vincent said in Function List incomplete:
I suspect it’s not this function, but rather what else is in your script that is causing the issue:
comments, newlines, mismatched braces … ?
Cheers.
OK, so this is really weird. I simply cut the entire function from the script, moved it above the function that immediately precedes it, saved it, and the function list automatically added it.
Testing further, I moved the other function elsewhere in the script, saved it, and the function that immediately follows that function now no longer shows up in the functions list.
Isolating the function in question, there is no issue with it displaying in the functions list. There must be something at the end of the function that is causing the issue.
A bunch of commenting, saving, uncommenting, saving, etc. brings it down to this single line:
LINKCMDOUT="$( nexec -i -l ${DSSVR} "${(e)BASELINKCMD} 2>/dev/null ; echo -e \"RESULT=\$?\" ; sleep 5 ; ${FINDCMD} /opt -maxdepth 1 -type l -ilname '*mqm*' -ls 2>/dev/null" )"
It doesn’t like the semi-colons.
-
Should this be logged as a bug or some sort of defect? Anyone have any suggestions on how to modify the bash.xml functionList file to accommodate the use of semi-colons?
I suspect that this part of the function node is causing the issue:
[^{;]*?\{ # no semi-colon until start of body
The line in question is within an if-then-else body, and there are lines elsewhere within my script inside other functions that are displayed in the functions list that use inline semi-colons in the same way that are not exhibiting this behavior within NP++.
Worst case scenario, it’s a minor inconvenience. Just hoping that someone a little more familiar with this code might have an idea.
Thanks!
-
@greg-michael said in Function List incomplete:
“RESULT=$?”
For my testing, it seems to be the escaped double-quotes in the expression you highlight:
... \"RESULT=\$?\" ...
If I change that part to:
... RESULT=\$? ...
All my functions show. If I have the escaped double-quotes in, then the function following that line does not appear in the function list.
Cheers.
-
@Michael-Vincent OK, I can buy that. Any suggestions on how to manage escaped quotes? I have those in other functions as well, and those functions appear in my functions list.
-
@greg-michael said in Function List incomplete:
I have those in other functions as well, and those functions appear in my functions list.
Interesting … ?
Can you post the entire script, or does it contain info you don’t want public?
Cheers.
-
@Michael-Vincent Let me take a look… I don’t think that there’s anything sensitive in it, but just to be safe…
-
@Michael-Vincent Is there a way to upload the script as an attachment, or do I simply need to paste it in a code block inline?
-
-
@Michael-Vincent Here you go…
#!/bin/nsh # set -x #GVM## Version: 2022.03.01 # Version: 2023.06.09 ################################################################################ ############# MQ_client_util.nsh ############# ################################################################################ # Author: Greg Michael # Date Created: 2021-08-27 # Description: This script is intended to be run from TSSA. # This script facilitates the installation, upgrade, downgrade, or # removal of the MQ Client on a server. It also checks for and if # necessary installs the BES Agent used for license auditing. # # Inputs: # ${NSH}.nsh -s "<host> [<host2> <hostN> ...]" [-d] [-h] [-p <#>] [-R|-U] [-y] # options enclosed in square brackets ([...]) are optional # -d Enable DEBUG output (optional, noisy) # -h Help - display this usage message # -p # (3) Patch Number # (3) optional for upgrades - will select # highest version available # -R (1) ROLLBACK - uninstall latest FP from target # (1) cannot be run with Uninstall option (-U) # -s "<list>" Hosts, enclosed in quotes, space separated (required) # -U (1) Uninstall MQ Client (optional) # (1) cannot be run with Rollback option (-R) # -y DRYRUN - execute DRYRUN (optional) # # # Notes: # Script can be run against multiple servers, but runs one at a time when # run outside TSSA (NSH Shell). # Servers must be passed in as a single option enclosed in double quotes # space separated, when run outside TSSA (NSH Shell). # Running without any options displays the usage. # Running without providing the -p option will automatically select and # install/upgrade to the highest available version. # Rollback and Uninstall are mutually exclusive options. # Rollback checks for a version below current that is not the 0-0 base. # Rollback and Upgrade check for and if necessary installs the BES Agent. # # # Error Codes: # code section description # ---- ------- ---------------------------------------------- # 100 main Unrecognized patch version # 101 main Failed to set patch version # 102 main Failed to set TARFILE # 103 main Requested version to remove is below installed # version # 104 env_check User mqm not found # 105 env_check Group mqm not found # 106 env_check MQ Server RPMs found installed # 107 env_check Error encountered creating paths on server # 108 install_bes Failed to install BES Agent # 109 install_bes Failed to copy actionsite.afxm file to path # 110 install_bes Failed to start BES Client on server # 111 copy_files Could not copy patch files from source server # 112 copy_files Failed to copy source files to target server # 113 copy_files Failed to unpack tarball on target server #GVM## 114 unpack_files Failed to copy BES Agent RPMs from source server # 114 unpack_files BES Agent RPMs not found on server #GVM## 115 unpack_files Failed to copy Corp actionsite.afxm file from source # 115 unpack_files Corp actionsite.afxm file not found on server # 116 install_mq Errors encountered during install/upgrade # 117 install_mq Failed to set primary instance on server # 118 install_mq Failed to install license on server # 119 rollback_mq Errors encountered during uninstall/rollback # 120 rollback_mq Failed to remove Patch RPMs (downgrade) # 121 rollback_mq Failed to set primary instance on server # 122 rollback_mq Failed to remove all MQ RPMs on server # 123 env_check Failed to remove .*tag files # 124 ptc_symlink Failed to create /opt/mqm symbolic link # 125 ptc_symlink Failed to remove /opt/mqm symbolic link # 126 unpack_files tar archive not found in DATAPATH on target #GVM## 127 unpack_files Failed to copy mn/actionsite.afxm file from source # 127 unpack_files PTC CPP actionsite.afxm file not found on server #GVM## 128 unpack_files Failed to copy og/actionsite.afxm file from source # 128 unpack_files PTC Ogden actionsite.afxm file not found on server # 129 env_check Unable to determine OS of server # 130 env_check Unable to determine install state on server # 131 rollback_mq No MQVERBASE PATCHVER patches found on server # 132 rollback_mq No MQSeries*_MQCV-*.rpm RPMs to remove on server # 133 rollback_mq Rollback requested, but no Fix Packs installed # 134 env_check IP Address not found in /etc/hosts # 135 env_check MQ Client version ${MAJVER} found - manual removal required # 136 env_check Multiple MQ Client installations detected # 137 install_mq Improper install detected. Missing *-0 RPMs # 138 rollback_mq Failed to set package manager for server # 139 env_check Failed to determine OS for server # 140 fix_install Errors detected after attempting to fix install # # History: # -------- --- ---------------------------------------------------------------- # 08/27/21 GVM Initial creation # 10/12/21 GVM Moved license acceptance before install command. Fixed infinite # loop during DRYRUN for install_mq function when checking results # for PATCHVER -gt VER check. Added creation of install.log file # on target host in MQCVPATH per request. Updated print_msg to only # print specific TYPE statements, not both when DEBUG or DRYRUN modes # are in use. # 11/18/21 GVM Added MAJVER variable. Added logic to allow removal of MQ Client # versions below 9.x. Added BESClientDeployTool and BESRelay RPMs # to correctly remove older BESClient installs. # 11/29/21 GVM Added MQVERBASEMIN to represent new minimum base version. # Added SWFINDCMD, TAGCHK, and TAGRM for finding and removing # .*tag files. # Added -T flag for indicating PTC install environment. Added # ptc_symlink function to check for and if necessary, create /opt/mqm # symbolic link to /usr/mqm/MQCV. # 03/01/22 GVM Massive updates across the entire script # 03/21/22 GVM Updated for migration of source files to shared file system. # Corrected for MQCVPATH check to include /opt/mqm for PTC servers. # Added error check for missing IP address in /etc/hosts. # Updated awk script to grab all digits after last period in version # output of dspmqver command for VER variable. # Added logic to force manual uninstall for PTC installations not # running version 9 clients and installed in /opt/mqm. # 04/12/22 GVM Updated locations for BES Client files to /hamq/software/besclient # Added new variable HABES # 04/19/22 GVM Added INSTCNT variable and logic to check for multiple installations # of MQ Client. Adjust for tarball extraction into MQCV/... path. # 01/06/23 GVM Added code to display installation output - if any - during an # install failure (exit code 116). Added RPMMQBASECNT to check count # of *-0 RPMs (required for Fix Pack install). Added check for # RPMMQBASECNT=0 when MQ RPMs are installed indicating improper install. # 02/16/23 GVM Updated for version 9.3.0-3. Modified HOSTS option to remove ',;:\t' # Removed FPVER-redundant since VER is used. Made some aesthetic # changes to logging in env_check function. # 06/09/23 GVM Updates... # ################################################################################ # VERY VERBOSE OUTPUT if (( $( echo -e "$@" | grep -ic "verbose") )) ; then set -x ; fi # ################################################################################ NSH="MQ_client_util" HH="$( date +%H )" # 15 MIN="$( date +%M )" # 45 DD="$( date +%d )" # 01 MM="$( date +%m )" # 01 MMDD="${MM}${DD}" # 0102 YYYY="$( date +%Y )" # 2009 APPPATH='/usr/mqm' APPPATHOUT="" #GVM#typeset -i BASECMDLVL=930 BESACTION="actionsite.afxm" BESAGENTBASE='BESAgent-' BESCHKOUT="" BESCLIENTPATH="/etc/opt/BESClient" BESCLIENTRPMS='BESAgent-|BESClientDeployTool-|BESRelay-' typeset -i BESINSTALL=0 CLEANCMD="" typeset -i CPP=0 DATAPATH='/var/mqm' DATAPATHOUT="" typeset -i DEBUG=0 DSPMQVER='/bin/dspmqver -i' typeset -i DRYRUN=0 typeset -i ERROR_CODE=0 ERRORDESC="" typeset -i EXISTING=0 FINDARGS="-name 'lost+found' -prune -o \( -type f -o -type d \) -a \! " FINDARGS+="\( -user 'mqm' -a -group 'mqm' \) -exec chown mqm:mqm {} \;" FINDCMD='/usr/bin/find' GETENT='/usr/bin/getent' GREPNC='grep --color=never' HABES='/hamq/software/besclient' HAMQ='/hamq/software/mq' HOSTS="" INSTSERVER="" IPADDR='0.0.0.0' LICCHK="" LINKCMD='ln -s ${(e)MQCVPATH} /opt/mqm' LOGPATH="" MAILX='/usr/bin/mailx' # default for Linux servers typeset -i MAJVER=0 typeset -i MAXCMDLVL=0 MQCVPATH="${APPPATH}/MQCV" MQCVPATHOUT="" MQINSTBASE='MQCV-' MQLICENSE="${DATAPATH}/MQCV/mqlicense.sh -accept 2>&1" MQRPMS='MQSeriesRuntime_ MQSeriesClient_ MQSeriesJava_ MQSeriesSDK_ MQSeriesJRE_ ' MQRPMS+='MQSeriesGSKit_ MQSeriesMan_ MQSeriesSamples_' _MQRPMS="" MQSERVERRPM='MQSeriesServer' #GVM#MQUPBASE='U930' #GVM#MQVERBASE='9.3.0-' MQVERBASEERE='9[.][0-9]+[.]0-' MQVERBASEMIN='0' MQVERSION="" typeset -i NEWINST=0 typeset -i OGDEN=0 typeset -i PATCHVER=0 PATHCHK="" typeset -i PTC=0 typeset -i ROLLBACK=0 RPM_CMD='/bin/rpm' RPMBASE='MQSeries' RPMCHK="${RPM_CMD} -qa | grep --color=never -iE \"(${RPMBASE}|${BESCLIENTRPMS}).*\"" typeset -i RPMCHKOUT=0 RPMINST="${RPM_CMD} --prefix ${MQCVPATH} -i" RPMINSTLIST="" typeset -i RPMMQBASECNT=0 RPMPLATFORM=".x86_64" RPMSUFFIX=".rpm" RPMUPDATE="${RPM_CMD} --prefix ${MQCVPATH} -U" RPMUPLIST="" SETMQINST="${MQCVPATH}/bin/setmqinst -p ${MQCVPATH} -i 2>&1" #GVM#SOURCEDIR="${DATAPATH}/MQCV-${MQINSTBASE}${MQVERBASE}" SOURCEDIR='${(e)DATAPATH}/MQCV-${(e)MQINSTBASE}${(e)MQVERBASE}' #GVM#SOURCEFILES='^${MQINSTBASE}${MQVERBASE}[0-9]+[.]tar[.]gz' SOURCEFILES='^${MQINSTBASE}${MQVERBASEERE}[0-9]+[.]tar[.]gz' SOURCEPATH="${HAMQ}/client" SOURCESVR='***********' STARS='********************************************************************************' STARTBESCMD="/etc/init.d/besclient restart 2>&1 ; sleep 5 ; /etc/init.d/besclient status" SVROS="" SWFINDCMD="${FINDCMD} ${APPPATH:=_none_} -type f -iname '*.*tag'" TAGCHK='${SWFINDCMD} -exec ls -l {} \;' TAGRM='${SWFINDCMD} -exec /bin/rm -vf {} \; 2>&1' TAR='/bin/tar' typeset -i TARNUM=0 typeset -i UNINSTALL=0 typeset -i VER=0 YUM='/usr/bin/yum' ZYPPER='/usr/bin/zypper' ################################################################################ # Functions ################################################################################ # critical_error ################################################################################ critical_error() { print_msg "ERROR_CODE=${ERROR_CODE}~nERRORDESC=${ERRORDESC}" "debug" if [[ ${ERROR_CODE} != 0 ]] then echo "(${MM}/${DD} $(date +%R)) ${NSH}: failed ERROR_CODE $ERROR_CODE!!!" | tee -a "${TMPLOG}" echo "Error description : ${ERRORDESC}" | tee -a "${TMPLOG}" # cat "${TMPLOG}" >> ${MAILFILE} # ${MAILX} -s "${NSH}.ksh had problems" $MAILSUPPORT < $MAILFILE fi cat "${TMPLOG}" | tee -a ${LOGFILE} exit ${ERROR_CODE} } ################################################################################ # usage ################################################################################ usage() { tee -a "${TMPLOG}" << EOF Usage: ${STARS} ${NSH}.nsh -s "<host> [<host2> <hostN> ...]" [-d] [-h] [-p <#>] [-R|-U] [-y] options enclosed in square brackets ([...]) are optional -d Enable DEBUG output (optional, noisy) -h Help - display this usage message -p # (3) Patch Number (3) optional for upgrades - will select highest version available -R (1) ROLLBACK - uninstall latest FP from target (1) cannot be run with Uninstall option (-U) -s "<list>" Hosts, enclosed in quotes, space separated (required) -U (1) Uninstall MQ Client (optional) (1) cannot be run with Rollback option (-R) -y DRYRUN - execute DRYRUN (optional) EOF cat "${TMPLOG}" >> ${LOGFILE} exit ${ERROR_CODE} } ################################################################################ # print_msg ################################################################################ print_msg() { unset MSG TYPE local MSG="${1}" local TYPE="${2}" # (U) convert variable to UPPERCASE # (L) convert variable to lowercase if [ "x${(L)TYPE}" = "xdebug" -o "x${(L)TYPE}" = "xdryrun" ] then # Prefix output with TYPE and display MSG="$( echo -e "${MSG}" | sed -e "s/~n/~n${(U)TYPE}: /g" -e 's/~n/\\n/g' )" if [ ${DEBUG} = 1 -a "x${(L)TYPE}" = "xdebug" ] then echo -e "${(U)TYPE}: ${MSG}" | tee -a "${TMPLOG}" fi if [ ${DRYRUN} = 1 -a "x${(L)TYPE}" = "xdryrun" ] then echo -e "${(U)TYPE}: ${MSG}" | tee -a "${TMPLOG}" fi else if [[ ${#MSG} -ge 76 ]] then echo -e "${STARS}\n${MSG}\n${STARS}" | tee -a "${TMPLOG}" else # Center output string between *'s across 80 columns padded by spaces echo -e "${STARS}\n* ${(j: :l:38:r:38:)MSG} *\n${STARS}" | tee -a "${TMPLOG}" fi fi }
-
@Michael-Vincent Part 2
################################################################################ # env_check ################################################################################ env_check() { print_msg "\n(${MM}/${DD} $(date +%R)) Started env_check" "debug" unset APPPATHOUT BESAGENTRPM BESCHKOUT CHKCMDS DATAPATHOUT EXISTING GRPID INSTCNT #GVM#unset INSTPATH IPADDR LICCHK MAJVER MAXCMDLVL MKPATH MKPATHOUT MQCVPATHOUT MQRPMS unset INSTPATH IPADDR LICCHK MAJVER MAXCMDLVL MKPATH MKPATHOUT MQCVPATHOUT _MQRPMS unset MQVERSION NEWINST OPTDIR OPTPATHOUT OSNAME PATHCHK RPMCHKOUT RPMSVRCHKOUT unset SVR TAGCNT USERID VER local APPPATHOUT="" local BESCHKOUT="" local CHKCMDS="" local DATAPATHOUT="" local GRPID=0 local INSTCNT=0 local MKPATH="" local MKPATHOUT="" local MQCVPATHOUT="" #GVM#local MQRPMS="" local OPTPATHOUT=0 local OSNAME="" local PATHCHK="" local RPMSVRCHKOUT=0 local TAGCNT=0 local SVR="${1}" local USERID=0 export BESAGENTRPM="${BESAGENTBASE}" export CPP=0 export _MQRPMS="" export MQVERSION="" export OGDEN=0 export OPTDIR=0 export PTC=0 export RPMCHKOUT=0 export RPMMQBASECNT=0 #GVM#if (( NEWMQVERBASE )) #GVM# then #GVM# export NEWMQVERBASE=0 #GVM# export MQVERBASE='9.2.0-' #GVM# print_msg "NEWMQVERBASE=${NEWMQVERBASE}~nMQVERBASE=${MQVERBASE}" "debug" #GVM#fi PATHCHK='${FINDCMD} /{usr,var,opt} -mindepth 1 -maxdepth 2 -type d \( -iname "mqm" -o ' PATHCHK+='-iname "mqcv" \) -exec ls -ld {} \; 2>/dev/null' print_msg "BESAGENTRPM=${BESAGENTRPM}~nPATHCHK=${(e)PATHCHK}~nSVR=${SVR}" "debug" # (e) Perform parameter expansion, command substitution and arithmetic expansion on the result. CHKCMDS="$( nexec -ncq -i -l ${SVR} sh -c "${(e)PATHCHK} ; ${RPMCHK} ; ${(e)TAGCHK} ; \ let USERID=\$( ${GETENT} passwd mqm | ${GREPNC} -c \"mqm\" ) ; \ let GRPID=\$( ${GETENT} group mqm | ${GREPNC} -c \"mqm\" ) ; \ IPADDR=\$( ${GREPNC} -iE \"${SVR%%.*}[. $]\" /etc/hosts | ${GREPNC} -v '::1' ) ; \ REL=\"\$( ls /etc/*-release | ${GREPNC} -iE \"(suse|redhat)\" | sed 's/[[:cntrl:]]*//g' )\" ; \ echo -e \"USERID=\${USERID}\\nGRPID=\${GRPID}\\nIPADDR=\${IPADDR}\\nREL=\${REL##*/}\"" )" print_msg "\nCHKCMDS=\n$( echo -e "${CHKCMDS}" | sed 's/\(^.*$\)/\\t\1/g' )" "debug" # Check for mqm user account and mqm group let GRPID=$( echo -e "${CHKCMDS}" | grep "GRPID=" | sed 's/[[:cntrl:]]*//g' | cut -f2 -d'=' ) let USERID=$( echo -e "${CHKCMDS}" | grep "USERID=" | sed 's/[[:cntrl:]]*//g' | cut -f2 -d'=' ) print_msg "USERID=${USERID}~nGRPID=${GRPID}" "debug" if ! (( ${GRPID} && ${USERID} )) then if (( ! ${USERID} )) then ERRORDESC="ERROR 104: User mqm is not present on ${SVR}." let ERROR_CODE=104 fi if (( ! ${GRPID} )) then ERRORDESC="ERROR 105: Group mqm not present on ${SVR}." let ERROR_CODE=105 fi critical_error fi # Parse output of CHKCMDS for use below. # (e) Perform parameter expansion, command substitution and arithmetic # expansion on the result. APPPATHOUT="$( echo -e "${CHKCMDS}" | grep -icE "${APPPATH}$" )" BESCHKOUT="$( echo -e "${CHKCMDS}" | grep -icE "${(e)BESAGENTRPM}.*" )" DATAPATHOUT="$( echo -e "${CHKCMDS}" | grep -icE "${DATAPATH}$" )" MQCVPATHOUT="$( echo -e "${CHKCMDS}" | grep -icE "(${MQCVPATH}|/opt/mqm)$" )" #GVM#MQRPMS="$( echo -e "${CHKCMDS}" | grep -iE "[.]x86(_64)?" )" _MQRPMS="$( echo -e "${CHKCMDS}" | grep -iE "[.]x86(_64)?" | \ sed 's/[[:cntrl:]]*//g' )" # Determine OS for correct RPM for BES Agent export SVROS="$( echo -e "${CHKCMDS}" | grep "REL=" | \ sed 's/[[:cntrl:]]*//g' | cut -f2 -d'=' | cut -f1 -d'-' )" if [[ -z ${SVROS} ]] then ERRORDESC="ERROR 139: Failed to determine OS for ${SVR}" let ERROR_CODE=139 critical_error else print_msg "SVROS=${SVROS}" "debug" fi # Extract IP Address for PTC executions export IPADDR="$( echo -e "${CHKCMDS}" | grep "IPADDR=" | cut -f2 -d'=' | awk '{print $1}' )" if [[ -z ${IPADDR} ]] then ERRORDESC="ERROR 134: IP Address not found in /etc/hosts on ${SVR}" let ERROR_CODE=134 critical_error else print_msg "IPADDR=${IPADDR}" "debug" fi if [[ $( echo -e "${IPADDR}" | grep -c '10.241.' ) == 1 ]] then export PTC=1 if [[ $( echo -e "${IPADDR}" | grep -c '10.241.1' ) == 1 ]] then export OGDEN=1 fi if [[ $( echo -e "${IPADDR}" | grep -c '10.241.2' ) == 1 ]] then export CPP=1 fi OPTPATHOUT="$( echo -e "${CHKCMDS}" | grep -icE "/opt/mqm$" )" if (( OPTPATHOUT )) ; then let OPTDIR=1 ; export OPTDIR ; fi print_msg "PTC=${PTC}~nOGDEN=${OGDEN}~nCPP=${CPP}~nOPTDIR=${OPTDIR}\ ~nOPTPATHOUT=${OPTPATHOUT}" "debug" fi export RPMCHKOUT="$( echo -e "${CHKCMDS}" | grep -iv "${MQSERVERRPM}" | \ sed 's/[[:cntrl:]]*//g' | grep -ic "${RPMBASE}" )" #GVM#export RPMMQBASECNT="$( echo -e "${CHKCMDS}" | grep -iv "${MQSERVERRPM}" \ #GVM#| grep -icE "${RPMBASE}.*-${MQVERBASE}${MQVERBASEMIN}" )" export RPMMQBASECNT="$( echo -e "${CHKCMDS}" | grep -iv "${MQSERVERRPM}" | \ sed 's/[[:cntrl:]]*//g' | grep -icE "${RPMBASE}.*-${MQVERBASEERE}${MQVERBASEMIN}" )" RPMSVRCHKOUT="$( echo -e "${CHKCMDS}" | grep -ic "${MQSERVERRPM}" )" TAGCNT="$( echo -e "${CHKCMDS}" | grep -icE '.*tag' )" print_msg "APPPATHOUT=${APPPATHOUT}~nBESCHKOUT=${BESCHKOUT}~nDATAPATHOUT=\ ${DATAPATHOUT}~nMQCVPATHOUT=${MQCVPATHOUT}~nRPMCHKOUT=${RPMCHKOUT}\ ~nRPMMQBASECNT=${RPMMQBASECNT}~nRPMSVRCHKOUT=${RPMSVRCHKOUT}~nTAGCNT=${TAGCNT}" "debug" # Validate that MQ Server RPMs are not installed # Abort now if this server has MQSeriesServer installed if [[ ${RPMSVRCHKOUT} != 0 ]] then ERRORDESC="ERROR 106: MQ Server RPMs installed on ${SVR}" let ERROR_CODE=106 critical_error fi # If MQ Client RPMs are not installed, install as new if [[ ${RPMCHKOUT} == 0 ]] then if [[ ${UNINSTALL} == 0 && ${ROLLBACK} == 0 ]] then print_msg "MQ Client RPMs not installed on ${SVR} - Initiating New Install" export NEWINST=1 export EXISTING=0 INSTPATH="${MQCVPATH}" # Validate /usr/mqm and /usr/mqm/MQCV exist. Create them and set correct # ownership and permissions if not found. if [[ ${APPPATHOUT} == 0 ]] then MKPATH="mkdir -p \"${MQCVPATH}\" && chown -R mqm \"${APPPATH}\"" MKPATH+=" ; chgrp -R mqm \"${APPPATH}\"" MKPATH+=" ; chmod -R u+rwx,g+rx,o+rx \"${APPPATH}\"" print_msg "MKPATH=${MKPATH}" "debug" elif [[ ${MQCVPATHOUT} == 0 ]] then MKPATH="mkdir -p \"${MQCVPATH}\" && chown -R mqm:mqm \"${APPPATH}\"" MKPATH+=" ; chgrp -R mqm \"${APPPATH}\"" MKPATH+=" ; chmod -R u+rwx,g+rx,o+rx \"${APPPATH}\"" print_msg "MKPATH=${MKPATH}" "debug" fi fi else if (( OPTDIR )) then MQCHK="$( nexec -i -l ${SVR} "/opt/mqm${DSPMQVER}" )" export INSTPATH="/opt/mqm" export EXISTING=1 export NEWINST=0 else MQCHK="$( nexec -i -l ${SVR} "${MQCVPATH}${DSPMQVER}" )" fi # Check for multiple installations of MQ Client let INSTCNT=$( echo -e "${MQCHK}" | sed -e 's/[[:cntrl:]]*//g' | \ grep -iE "^(Version|InstPath|InstName|Primary):" | \ sed 's/[[:cntrl:]]*//g' | wc -l | sed -e 's/[[:space:]]*//g' ) print_msg "\nMQCHK=\n${MQCHK}~nINSTCNT=${INSTCNT}" "debug" if [[ ${INSTCNT} != 4 ]] then ERRORDESC="ERROR 136: Multiple installations of MQ Client detected in /etc/opt/mqm/mqinst.ini \ on ${SVR}" let ERROR_CODE=136 if [[ -n ${MQCHK} ]] ; then print_msg "MQCHK=\n${MQCHK}" ; fi critical_error fi # Check for existing MQ Client path if [[ ${MQCVPATHOUT} == 1 ]] then export EXISTING=1 export NEWINST=0 MQCHK="$( echo -e "${MQCHK}" | sed 's/[[:cntrl:]]*//g' )" # Determine Install Path export INSTPATH="$( echo -e "${MQCHK}" | \ awk -F': ' '$0 ~ /^InstPath:/ {print $2}' | sed 's/^[ ]*//g' )" # Determine Major Version export MAJVER="$( echo -e "${MQCHK}" | \ awk -F': ' '$0 ~ /^Version:/ { sub(/[ ]*/,"",$2) ; print substr($2,1,1) }' )" # Grab MaxCmdLvl from dspmqver output export MAXCMDLVL="$( echo -e "${MQCHK}" | \ awk -F': ' '$0 ~ /^MaxCmdLevel:/ { sub(/[ ]*/,"",$2) ; print $2 }' )" # Update MQVERBASE if MaxCmdLevel is greater than current Base level if [[ ${MAXCMDLVL} > ${BASECMDLVL} ]] then export MQVERBASE="$( echo -e "${MQCHK}" | \ awk -F': ' '$0 ~ /^Version:/ { sub(/[ ]*/,"",$2) ; print substr($2,1,5)"-" }' )" print_msg "New MQVERBASE\nMQVERBASE=${MQVERBASE}" "debug" fi # Extract currently installed version from dspmqver output export MQVERSION="$( echo -e "${MQCHK}" | \ awk -F': ' '$0 ~ /^Version:/ { sub(/[ ]*/,"",$2) ; print substr($2,1,5) "-" substr($2,7,1) }' )" # Grab the Fix Pack part of the version (last number(s) after the final period) # i.e. - 8.0.0.15, 9.2.0.4 # match looks for the last characters starting from the period until # the end of the line that do NOT include a period, and then add 1 # to the value for the substring command export VER="$( echo -e "${MQCHK}" | \ awk -F': ' '$0 ~ /^Version:/ {print substr($2,match($2,/[.][^.]*$/)+1,1)}' )" if [[ ${MAJVER} != 9 ]] then print_msg "MQ Client version ${MAJVER} found - manual removal required." ERRORDESC="ERROR 135: MQ Client version ${MAJVER} found - manual removal required." let ERROR_CODE=135 critical_error fi export LICCHK="$( echo -e "${MQCHK}" | \ awk -F': ' '$0 ~ /^LicenseType:/ {print $2}' )" if (( EXISTING )) then print_msg "MQ Client ${MQVERSION} found installed at ${INSTPATH} on ${SVR}" #GVM#print_msg "RPM versions installed:\n${MQRPMS}" print_msg "RPM versions installed:\n${_MQRPMS}" #GVM# print_msg "MAJVER=${MAJVER}~nVER=${VER}~nLICCHK=${LICCHK}" "debug" print_msg "MAJVER=${MAJVER}~nMAXCMDLVL=${MAXCMDLVL}~nVER=${VER}~nLICCHK=${LICCHK}\ ~nMQVERSION=${MQVERSION}" "debug" fi elif [[ ${OPTDIR} == 0 ]] then ERRORDESC="ERROR 130: Unable to determine install state on ${SVR}" let ERROR_CODE=130 critical_error fi fi print_msg "INSTPATH=${INSTPATH}~nEXISTING=${EXISTING}~nNEWINST=${NEWINST}" "debug" # Validate /var/mqm exists. Create it and set correct ownership and permissions # if not found. if [[ ${DATAPATHOUT} == 0 && ${NEWINST} == 1 ]] then if [[ -n ${MKPATH} ]] then MKPATH+=" ; mkdir -p \"${DATAPATH}\" && chown mqm \"${DATAPATH}\"" MKPATH+=" ; chgrp mqm \"${DATAPATH}\" ; chmod u+rwx,g+rwxs,o+rx \"${DATAPATH}\" " else MKPATH="mkdir -p \"${DATAPATH}\" && chown mqm \"${DATAPATH}\" ; " MKPATH+="chgrp mqm \"${DATAPATH}\" ; chmod u+rwx,g+rx,o+rx \"${DATAPATH}\" " fi print_msg "MKPATH=${MKPATH}" "debug" fi # If one or more paths do not exist, create it/them. if [[ -n ${MKPATH} ]] then if (( DRYRUN )) then print_msg "\nnexec -i -l ${SVR} \"${MKPATH}\"" "dryrun" else nexec -i -l ${SVR} "${MKPATH}" if [[ $? != 0 ]] then ERRORDESC="ERROR 107: Error encountered while creating paths on ${SVR}" let ERROR_CODE=107 critical_error fi fi fi # Check BESClient installation if [[ ${BESCHKOUT} == 0 ]] then if [[ ${UNINSTALL} == 0 && ${ROLLBACK} == 0 ]] then print_msg "BES Agent missing on ${SVR} - installing" export BESINSTALL=1 #GVM# # Determine OS for correct RPM for BES Agent #GVM# export SVROS="$( echo -e "${CHKCMDS}" | grep "REL=" | cut -f2 -d'=' | cut -f1 -d'-' )" if [ "x${(L)SVROS}" = "xsuse" ] then export BESAGENTRPM="${BESAGENTBASE}*-sle*${RPMPLATFORM}${RPMSUFFIX}" elif [ "x${(L)SVROS}" = "xredhat" ] then export BESAGENTRPM="${BESAGENTBASE}*-rhe*${RPMPLATFORM}${RPMSUFFIX}" else ERRORDESC="ERROR 129: Unable to determine OS of ${SVR}" let ERROR_CODE=129 critical_error fi print_msg "BESAGENTRPM=${BESAGENTRPM}" "debug" else export BESINSTALL=0 fi print_msg "BESINSTALL=${BESINSTALL}" "debug" fi # Check for existence of .*tag files - remove if found #GVM#if (( TAGCNT )) #GVM# then #GVM# if (( DRYRUN )) #GVM# then #GVM# # (e) Perform parameter expansion, command substitution and arithmetic #GVM# # expansion on the result. #GVM# print_msg "\nnexec -i -l ${SVR} \"${(e)TAGRM}\"" "dryrun" #GVM# else #GVM# nexec -i -l ${SVR} "${(e)TAGRM}" #GVM# if [[ $? != 0 ]] #GVM# then #GVM# ERRORDESC="ERROR 123: Failed to remove .*tag file(s) on ${SVR}." #GVM# let ERROR_CODE=123 #GVM# critical_error #GVM# fi #GVM# fi #GVM#fi print_msg "\n(${MM}/${DD} $(date +%R)) End env_check" "debug" }
-
@Michael-Vincent Part 3
################################################################################ # copy_files ################################################################################ copy_files() { print_msg "\n(${MM}/${DD} $(date +%R)) Started copy_files" "debug" unset BASECPRESULT BKPFMT BUILDDIR CLEANCMD CPRESULT DIRCHK FILE SRCPATH SRCSVR SVR local BASECPRESULT=0 local BKPFMT=".${DD}-${MM}-${YYYY}_${HH}${MM}" local BUILDDIR="${3}" local CPRESULT=0 local DIRCHK="" local FILE="${4}" local SRCSVR="${2}" local SVR="${1}" # Setup source path to copy files from # /hamq/software/mq/client local SRCPATH="${SRCSVR}${SOURCEPATH}" #GVM#print_msg "BKPFMT=${BKPFMT}~nBUILDDIR=${BUILDDIR}~nFILE=${FILE}~nSRCSVR=${SRCSVR}\ #GVM#~nSVR=${SVR}" "debug" print_msg "BKPFMT=${BKPFMT}~nBUILDDIR=${BUILDDIR}~nFILE=${FILE}~nSRCSVR=${SRCSVR}\ ~nSVR=${SVR}" "debug" # Copy install and patch files from source to target if [[ -n ${FILE} ]] then # DATAPATH includes leading '/' # If remnants of previous tarballs remain, remove them. CLEANCMD='if [[ -d ${DATAPATH:=/var/mqm}/MQCV ]] ; then ' CLEANCMD+='/bin/rm -dfR ${DATAPATH:=/var/mqm}/MQCV ; fi ; ' CLEANCMD+='if [[ \$(ls ${DATAPATH:=/var/mqm} | grep -cE "MQCV-[0-9][.][0-9]+[.][0-9]+[-][0-9]+[.]tar[.]gz(.*)?" ) ]] ; then ' CLEANCMD+='/bin/rm -f ${DATAPATH:=/var/mqm}/MQCV-*.*.*-*.tar.gz* ; fi ; ' CLEANCMD+='if [[ -d ${DATAPATH:=/var/mqm}/BESClient ]] ; then ' CLEANCMD+='/bin/rm -dfR ${DATAPATH:=/var/mqm}/BESClient ; fi' export CLEANCMD print_msg "\nCLEANCMD=${(e)CLEANCMD}" "debug" #GVM# nexec -i -l ${SVR} "/bin/rm -dfR ${DATAPATH:=/var/mqm}/MQCV ; \ #GVM#/bin/rm -dfR ${DATAPATH:=/var/mqm}/BESClient" #GVM# nexec -i -l ${SVR} "/bin/rm -dfR ${DATAPATH:=/var/mqm}/MQCV ; \ #GVM#/bin/rm -f ${DATAPATH:=/var/mqm}/MQCV-*.*.*-*.tar.gz ; /bin/rm -dfR ${DATAPATH:=/var/mqm}/BESClient" if (( DRYRUN )) then print_msg "nexec -i -l ${SVR} \"${(e)CLEANCMD}\"" "dryrun" print_msg "\ncp -bfuvs \"${BKPFMT}\" //${SRCPATH}/${FILE} \ //${SVR}${DATAPATH}" "dryrun" else nexec -i -l ${SVR} "${(e)CLEANCMD}" cp -bfuvs "${BKPFMT}" //${SRCPATH}/${FILE} //${SVR}${DATAPATH} let CPRESULT=$? fi #GVM# else #GVM# # If tarball is missing on source server, check for build directory #GVM# DIRCHK="$( ls -d //${SRCSVR}${BUILDDIR} )" #GVM# DIRCHK="$( ls -d //${SRCSVR}${BUILDDIR} 2>/dev/null )" #GVM# print_msg "DIRCHK=${DIRCHK}" "debug" #GVM# if [[ -n ${DIRCHK} ]] #GVM# then #GVM# # BUILDDIR and DATAPATH include leading '/' #GVM# if (( DRYRUN )) #GVM# then #GVM# print_msg "\ncp -puvr //${SRCSVR}${BUILDDIR}/* //${SVR}${DATAPATH}" "dryrun" #GVM# else #GVM# cp -puvr //${SRCSVR}${BUILDDIR}/* //${SVR}${DATAPATH} #GVM# let CPRESULT=$? #GVM# fi #GVM# else #GVM# ERRORDESC="ERROR 111: Could not copy patch ${PATCHVER} files from \ #GVM#${SRCSVR}:${BUILDDIR} to ${SVR}" #GVM# #GVM# let ERROR_CODE=111 #GVM# critical_error #GVM# fi fi print_msg "CPRESULT=${CPRESULT}" "debug" # Verify copy success if [[ ${CPRESULT} != 0 ]] then ERRORDESC="ERROR 112: Failed to copy source files to ${SVR}" let ERROR_CODE=112 critical_error else #GVM# unpack_files ${SVR} unpack_files ${SVR} "${FILE}" fi print_msg "\n(${MM}/${DD} $(date +%R)) End copy_files" "debug" } ################################################################################ # unpack_files ################################################################################ unpack_files() { print_msg "\n(${MM}/${DD} $(date +%R)) Started unpack_files" "debug" unset ACTIONFILE BESDATAPATH CPPACTIONFILE CPRESULT OGNACTIONFILE RESULT RPMFILES unset SPATH TGT TFILE UNPACK local ACTIONFILE="" local BESDATAPATH='//${TGT}${DATAPATH}/BESClient' local CPPACTIONFILE="" local CPRESULT=0 local OGNACTIONFILE="" local RESULT=99 local RPMFILES=0 local SPATH="//${SOURCESVR}${HABES}" local TGT="${1}" #GVM#local TFILE="" local TFILE="${2}" local UNPACK="" # Check for tarball on target server # (e) Perform parameter expansion, command substitution and arithmetic # expansion on the result. #GVM#TFILE="$( ls //${TGT}${DATAPATH} 2>/dev/null | grep -iE "${(e)SOURCEFILES}$" | \ #GVM#grep -i "${MQVERBASE}${PATCHVER}" )" if [[ ${#TFILE} == 0 ]] then TFILE="$( ls //${TGT}${DATAPATH} 2>/dev/null | grep -iE "${(e)SOURCEFILES}$" \ | sed 's/[[:cntrl:]]*//g' )" fi print_msg "BESDATAPATH=${(e)BESDATAPATH}~nDATAPATH=${DATAPATH}~nSPATH=${SPATH}~nTGT=${TGT}~n\ TFILE=${TFILE}" "debug" if [[ -n ${TFILE} ]] then # DATAPATH includes leading '/' if (( DRYRUN )) then print_msg "\nnexec -i -l ${TGT} \"${TAR} -C ${DATAPATH} -zxf ${DATAPATH}/${TFILE} \ ; echo -e \\\"RESULT=\\\$?\\\"\"" "dryrun" let RESULT=0 else UNPACK="$( nexec -i -l ${TGT} "${TAR} -C ${DATAPATH} -zxf ${DATAPATH}/${TFILE} \ ; echo -e \"RESULT=\$?\"" )" let RESULT=$( echo -e "${UNPACK}" | grep "RESULT=" | \ sed 's/[[:cntrl:]]*//g' | cut -f2 -d'=' ) print_msg "UNPACK=${UNPACK}~nRESULT=${RESULT}" "debug" fi if [[ ${RESULT:=99} != 0 ]] then ERRORDESC="ERROR 113: Failed to unpack ${TFILE} on ${TGT}" let ERROR_CODE=113 if [[ -n "${UNPACK}" ]] ; then print_msg "UNPACK=\n${UNPACK}" ; fi critical_error else # Force owner:group mqm:mqm for new installs if (( NEWINST )) then if (( DRYRUN )) then print_msg "\nnexec -i -l ${TGT} \"${FINDCMD} ${DATAPATH} \ ${FINDARGS}\"" "dryrun" else nexec -i -l ${TGT} "${FINDCMD} ${DATAPATH} ${FINDARGS}" fi fi fi else if (( ! DRYRUN )) then ERRORDESC="ERROR 126: tar archive not found in ${DATAPATH} on ${TGT}" let ERROR_CODE=126 critical_error fi fi # If BESAgent is not installed, ensure install files are available if [[ ${BESINSTALL} == 1 ]] then # Validate existence of actionsite.afxm and BESAgent RPM files BESFILES="$( find ${(e)BESDATAPATH} -type f -exec ls {} \; 2>/dev/null )" ACTIONFILE="$( echo -e "${BESFILES}" | grep -ic "/corp/${BESACTION}" )" CPPACTIONFILE="$( echo -e "${BESFILES}" | grep -ic "mn/${BESACTION}" )" OGNACTIONFILE="$( echo -e "${BESFILES}" | grep -ic "og/${BESACTION}" )" RPMFILES="$( echo -e "${BESFILES}" | grep -icE "${BESAGENTBASE}.*[.]rpm" )" print_msg "\nBESFILES=\n$( echo -e "${BESFILES}" | sed 's/\(^.*$\)/\\t \1/g' )\ ~nACTIONFILE=${ACTIONFILE}~nCPPACTIONFILE=${CPPACTIONFILE}~nOGNACTIONFILE=\ ${OGNACTIONFILE}~nRPMFILES=${RPMFILES}" "debug" # If any files are missing, retrieve from SOURCESVR if [[ ${RPMFILES} != 2 || ${ACTIONFILE} == 0 || ${CPPACTIONFILE} == 0 || \ ${OGNACTIONFILE} == 0 ]] then # Retrieve BESAgent RPM file if not found if [[ ${RPMFILES} != 2 ]] then if (( ! DRYRUN )) then #GVM# print_msg "\ncp -puv ${SPATH}/*.rpm ${(e)BESDATAPATH}/" "dryrun" #GVM# else #GVM# if [[ ! -d ${(e)BESDATAPATH} ]] #GVM# then #GVM# if (( DRYRUN )) #GVM# then #GVM# print_msg "nexec -i -l ${TGT} sh -c \"mkdir -p ${DATAPATH}/BESClient ; \ #GVM#chown mqm:mqm ${DATAPATH}/BESClient\"" #GVM# #GVM# else #GVM# nexec -i -l ${TGT} sh -c "mkdir -p ${DATAPATH}/BESClient ; \ #GVM#chown mqm:mqm ${DATAPATH}/BESClient" #GVM# #GVM# fi #GVM# fi #GVM# cp -puv ${SPATH}/*.rpm ${(e)BESDATAPATH}/ #GVM# if [[ $? != 0 ]] #GVM# then #GVM# ERRORDESC="ERROR 114: Failed to copy BES Agent RPMs from \ #GVM#${SOURCESVR} to ${TGT}" ERRORDESC="ERROR 114: BES Agent RPMs not found on ${TGT}" let ERROR_CODE=114 critical_error #GVM# fi #GVM# fi fi if (( ! PTC )) then #GVM# # Retrieve actionsite.afxm file if not found if [[ ${ACTIONFILE} == 0 ]] then if (( ! DRYRUN )) then #GVM# print_msg "\ncp -puv ${SPATH}/corp/${BESACTION} \ #GVM#${(e)BESDATAPATH}/corp/" "dryrun" #GVM# #GVM# else #GVM# if [[ ! -d ${(e)BESDATAPATH}/corp ]] #GVM# then #GVM# if (( DRYRUN )) #GVM# then #GVM# print_msg "nexec -i -l ${TGT} sh -c \"mkdir -p ${DATAPATH}/BESClient/corp ; \ #GVM#chown mqm:mqm ${DATAPATH}/BESClient/corp\"" #GVM# #GVM# else #GVM# nexec -i -l ${TGT} sh -c "mkdir -p ${DATAPATH}/BESClient/corp ; \ #GVM#chown mqm:mqm ${DATAPATH}/BESClient/corp" #GVM# #GVM# fi #GVM# fi #GVM# cp -puv ${SPATH}/corp/${BESACTION} ${(e)BESDATAPATH}/corp/ #GVM# if [[ $? != 0 ]] #GVM# then #GVM# ERRORDESC="ERROR 115: Failed to copy Corporate ${BESACTION} file \ #GVM#from ${SOURCESVR} to ${TGT}" ERRORDESC="ERROR 115: Corporate ${BESACTION} file not found on ${TGT}" let ERROR_CODE=115 critical_error #GVM# fi #GVM# fi fi else #GVM# # Retrieve mn/actionsite.afxm file if not found if [[ ${CPPACTIONFILE} == 0 ]] then if (( ! DRYRUN )) then #GVM# print_msg "\ncp -puv ${SPATH}/mn/${BESACTION} \ #GVM#${(e)BESDATAPATH}/mn/" "dryrun" #GVM# #GVM# else #GVM# if [[ ! -d ${(e)BESDATAPATH}/mn ]] #GVM# then #GVM# if (( DRYRUN )) #GVM# then #GVM# print_msg "nexec -i -l ${TGT} sh -c \"mkdir -p ${DATAPATH}/BESClient/mn ; \ #GVM#chown mqm:mqm ${DATAPATH}/BESClient/mn\"" #GVM# #GVM# else #GVM# nexec -i -l ${TGT} sh -c "mkdir -p ${DATAPATH}/BESClient/mn ; \ #GVM#chown mqm:mqm ${DATAPATH}/BESClient/mn" #GVM# #GVM# fi #GVM# fi #GVM# cp -puv ${SPATH}/mn/${BESACTION} ${(e)BESDATAPATH}/mn/ #GVM# if [[ $? != 0 ]] #GVM# then #GVM# ERRORDESC="ERROR 127: Failed to copy PTC CPP ${BESACTION} \ #GVM#file from ${SOURCESVR} to ${TGT}" ERRORDESC="ERROR 127: PTC CPP ${BESACTION} file not found on ${TGT}" let ERROR_CODE=127 critical_error #GVM# fi #GVM# fi fi #GVM# # Retrieve og/actionsite.afxm file if not found if [[ ${OGNACTIONFILE} == 0 ]] then if (( ! DRYRUN )) then #GVM# print_msg "\ncp -puv ${SPATH}/og/${BESACTION} \ #GVM#${(e)BESDATAPATH}/og/" "dryrun" #GVM# #GVM# else #GVM# if [[ ! -d ${(e)BESDATAPATH}/og ]] #GVM# then #GVM# if (( DRYRUN )) #GVM# then #GVM# print_msg "nexec -i -l ${TGT} sh -c \"mkdir -p ${DATAPATH}/BESClient/og ; \ #GVM#chown mqm:mqm ${DATAPATH}/BESClient/og\"" #GVM# #GVM# else #GVM# nexec -i -l ${TGT} sh -c "mkdir -p ${DATAPATH}/BESClient/og ; \ #GVM#chown mqm:mqm ${DATAPATH}/BESClient/og" #GVM# #GVM# fi #GVM# fi #GVM# cp -puv ${SPATH}/og/${BESACTION} ${(e)BESDATAPATH}/og/ #GVM# if [[ $? != 0 ]] #GVM# then #GVM# ERRORDESC="ERROR 128: Failed to copy PTC OGN ${BESACTION} \ #GVM#file from ${SOURCESVR} to ${TGT}" ERRORDESC="ERROR 128: PTC OGN ${BESACTION} file not found on ${TGT}" let ERROR_CODE=128 critical_error #GVM# fi #GVM# fi fi fi fi fi print_msg "\n(${MM}/${DD} $(date +%R)) End unpack_files" "debug" } ################################################################################ # install_bes ################################################################################ install_bes() { print_msg "\n(${MM}/${DD} $(date +%R)) Started install_bes" "debug" unset BESINSTCMDS BESINSTOUT COPYBESCMD CPBES CPRESULT RESULT STARTBES TARGET local BESINSTCMDS="" local BESINSTOUT="" local COPYBESCMD="" local CPBES="" local CPRESULT=99 local RESULT=99 local STARTBES="" local TARGET="${1}" BESINSTCMDS="mkdir -p \"${BESCLIENTPATH}\" && chmod u+rwx,g+rx,o+rx \"${BESCLIENTPATH}\"" BESINSTCMDS+=" ; ${RPM_CMD} -i ${DATAPATH}/BESClient/${BESAGENTRPM} 2>&1 | " BESINSTCMDS+="tee /tmp/besinstall.log ; echo -e \"RESULT=\$?\"" print_msg "BESINSTCMDS=${BESINSTCMDS}~nTARGET=${TARGET}" "debug" if (( DRYRUN )) then print_msg "\nnexec -i -l ${TARGET} \"${BESINSTCMDS}\"" "dryrun" else if [[ ${ROLLBACK} == 1 || ${PATCHVER} == ${VER} ]] then unpack_files ${TARGET} fi BESINSTOUT="$( nexec -i -l ${TARGET} "${BESINSTCMDS}" )" BESINSTOUT="$( echo -e "${BESINSTOUT}" | sed 's/[[:cntrl:]]*//g' )" let RESULT="$( echo -e "${BESINSTOUT}" | grep "RESULT=" | \ sed 's/[[:cntrl:]]*//g' | cut -f2 -d'=' )" print_msg "\nBESINSTOUT=\n${BESINSTOUT}~nRESULT=${RESULT}" "debug" fi if [[ ${RESULT:=99} != 0 ]] then ERRORDESC="ERROR 108: Failed to install ${BESAGENTRPM} on ${TARGET}" let ERROR_CODE=108 if [[ -n "${BESINSTOUT}" ]] ; then print_msg "BESINSTOUT=\n${BESINSTOUT}" ; fi critical_error else # Copy actionsite.afxm file to /etc/opt/BEClient on TARGET if (( ! PTC )) then COPYBESCMD="cp ${DATAPATH}/BESClient/corp/${BESACTION} ${BESCLIENTPATH} 2>&1 && " elif (( CPP )) then COPYBESCMD="cp ${DATAPATH}/BESClient/mn/${BESACTION} ${BESCLIENTPATH} 2>&1 && " elif (( OGDEN )) then COPYBESCMD="cp ${DATAPATH}/BESClient/og/${BESACTION} ${BESCLIENTPATH} 2>&1 && " fi COPYBESCMD+="echo -e \"RESULT=\$?\" ; chmod u+rw,g-rwx,o-rwx ${BESCLIENTPATH}/${BESACTION}" print_msg "\nCOPYBESCMD=${COPYBESCMD}" "debug" if (( DRYRUN )) then print_msg "\nnexec -i -l ${TARGET} \"${COPYBESCMD}\"" "dryrun" else CPBES="$( nexec -i -l ${TARGET} "${COPYBESCMD}" )" let CPRESULT="$( echo -e "${CPBES}" | grep "RESULT=" | \ sed 's/[[:cntrl:]]*//g' | cut -f2 -d'=' )" print_msg "CPBES=${CPBES}~nCPRESULT=${CPRESULT}" "debug" if [[ ${CPRESULT:=99} != 0 ]] then ERRORDESC="ERROR 109: Failed to copy ${BESACTION} to ${BESCLIENTPATH} \ on ${TARGET}" let ERROR_CODE=109 if [[ -n "${CPBES}" ]] ; then print_msg "CPBES=\n${CPBES}" ; fi critical_error fi fi print_msg "STARTBESCMD=${STARTBESCMD}" "debug" if (( DRYRUN )) then print_msg "\nnexec -i -l ${TARGET} \"${STARTBESCMD}\"" "dryrun" else STARTBES="$( nexec -i -l ${TARGET} "${STARTBESCMD}" )" STARTBES="$( echo -e "${STARTBES}" | sed 's/[[:cntrl:]]*//g' )" print_msg "STARTBES=${STARTBES}" "debug" let BESSTATUS="$( echo -e "${STARTBES}" | grep -i "besclient" | \ sed 's/[[:cntrl:]]*//g' | grep -ic "running" )" if [[ ${BESSTATUS:=0} == 0 ]] then ERRORDESC="ERROR 110: Failed to start BESClient on ${TARGET}" let ERROR_CODE=110 if [[ -n "${STARTBES}" ]] ; then print_msg "STARTBES=\n${STARTBES}\n\ BESSTATUS=${BESSTATUS}" ; fi critical_error fi fi fi print_msg "\n(${MM}/${DD} $(date +%R)) End install_bes" "debug" }
-
@Michael-Vincent Part 4
################################################################################ # install_mq ################################################################################ install_mq() { print_msg "\n(${MM}/${DD} $(date +%R)) Started install_mq" "debug" unset INSTSERVER MQINSTCMD MQINSTOUT RESULT RPMS SETMQINSTCMD # Cannot use local INSTSERVER or it gets reset after calling rollback_mq INSTSERVER="${1}" local MQINSTCMD="" local MQINSTOUT="" local RPMS="${2}" local RESULT=99 local SETMQINSTCMD="${SETMQINST}" if (( NEWINST )) then MQINSTCMD="${RPMINST} ${RPMS} 2>&1 | tee /tmp/mqinstall.log ; echo -e \"RESULT=\$?\"" else #GVM# # If we're upgrading minor versions (9.2 -> 9.3) MAXCMDLVL will be < BASECMDLVL # so install base RPMs first. if [[ ${MAXCMDLVL} < ${BASECMDLVL} ]] then #GVM# print_msg "Currently installed version is below v${MQVERBASE}${MQVERBASEMIN}. Proceeding with removal." print_msg "Currently installed version ${MQVERSION} is below v${MQVERBASE}${MQVERBASEMIN}. \ Proceeding with replacement." export UNINSTALL=1 rollback_mq ${INSTSERVER} export UNINSTALL=0 # Reset environment variables env_check ${INSTSERVER} copy_files ${INSTSERVER} ${SOURCESVR} "${(e)SOURCEDIR}${PATCHVER}" "${TARFILE}" fi MQINSTCMD="${RPMUPDATE} ${RPMS} 2>&1 | tee /tmp/mqinstall.log ; echo -e \"RESULT=\$?\"" fi #GVM## Prevent attempts to execute setmqinst if it doesn't exist #GVM#if [[ ! -f //${INSTSERVER}/${MQCVPATH}/bin/setmqinst ]] #GVM# then #GVM# SETMQINSTCMD="" #GVM#fi print_msg "\nMQINSTCMD=${MQINSTCMD}~n\nRPMS=${RPMS}~nINSTSERVER=${INSTSERVER}\ ~nSETMQINSTCMD=${SETMQINSTCMD}" "debug" if (( DRYRUN )) then #GVM# print_msg "\nnexec -i -l ${INSTSERVER} \"${MQLICENSE} ; ${SETMQINSTCMD}\"" "dryrun" #GVM# print_msg "\nnexec -i -l ${INSTSERVER} \"${MQINSTCMD}\"" "dryrun" # Prevent attempts to execute setmqinst if it doesn't exist if [[ ! -f //${INSTSERVER}/${MQCVPATH}/bin/setmqinst ]] then #GVM# SETMQINSTCMD="" print_msg "\nnexec -i -l ${INSTSERVER} \"${MQLICENSE}\"" "dryrun" else print_msg "\nnexec -i -l ${INSTSERVER} \"${MQLICENSE} ; ${SETMQINSTCMD}\"" "dryrun" fi print_msg "\nnexec -i -l ${INSTSERVER} \"${MQINSTCMD}\"" "dryrun" else # Prevent attempts to execute setmqinst if it doesn't exist if [[ -f //${INSTSERVER}/${MQCVPATH}/bin/setmqinst ]] then # Accept license and set Primary Instance MQLICOUT="$( nexec -i -l ${INSTSERVER} "${MQLICENSE} ; ${SETMQINSTCMD}" 2>/dev/null )" print_msg "\nMQLICOUT=\n${MQLICOUT}" "debug" fi # install MQ client MQINSTOUT="$( nexec -i -l ${INSTSERVER} "${MQINSTCMD}" )" let RESULT=$( echo -e "${MQINSTOUT}" | grep "RESULT=" | \ sed 's/[[:cntrl:]]*//g' | cut -f2 -d '=' ) #GVM# print_msg "\nMQLICOUT=\n${MQLICOUT}~n\nMQINSTOUT=\n${MQINSTOUT:-'no output'}~n\ #GVM#RESULT=${RESULT}" "debug" print_msg "\nMQINSTOUT=\n${MQINSTOUT:-'no output'}~nRESULT=${RESULT}" "debug" fi if (( ! DRYRUN )) then if [[ ${RESULT:=99} == 0 ]] then env_check ${INSTSERVER} print_msg "PATCHVER=${PATCHVER}~nVER=${VER}" "debug" # Validate installation if [[ ${EXISTING} != 1 || ${#INSTPATH} == 0 ]] then ERRORDESC="ERROR 117: Failed to set Primary Instance on ${INSTSERVER}" let ERROR_CODE=117 if [[ -n "${MQLICOUT}" ]] ; then print_msg "MQLICOUT=\n${MQLICOUT}" ; fi critical_error # if installed version VER is below the patch version PATCHVER, install patch RPMs #GVM# elif [[ ${PATCHVER} -gt ${VER} ]] elif [[ ${BASECMDLVL}${PATCHVER} -gt ${MAXCMDLVL}${VER} ]] then # Validate proper installation if [[ ${RPMCHKOUT} > 8 && ${RPMMQBASECNT} != 8 ]] then ERRORDESC="ERROR 137: Improper installation detected!" ERRORDESC+=" Missing ${MQSeries}*-${MQVERBASE}${MQVERBASEMIN} RPMs!" let ERROR_CODE=137 critical_error fi print_msg "Upgrading MQ Client version ${MQVERBASE}${VER} \ found at ${INSTPATH} on ${INSTSERVER}" install_mq ${host} "${RPMUPLIST}" # Accept license and set Primary Instance MQLICOUT="$( nexec -i -l ${host} "${MQLICENSE} ; ${SETMQINSTCMD}" )" print_msg "\nMQLICOUT=\n${MQLICOUT}" "debug" fi # Validate license status if [ "x${LICCHK}" = "xLicense not accepted" ] then ERRORDESC="ERROR 118: Failed to install license on ${INSTSERVER}" let ERROR_CODE=118 if [[ -n "${MQLICOUT}" ]] ; then print_msg "MQLICOUT=\n${MQLICOUT}" ; fi critical_error fi else ERRORDESC="ERROR 116: Errors encountered during install/upgrade on ${INSTSERVER}" let ERROR_CODE=116 if [[ -n "${MQINSTOUT}" ]] ; then print_msg "MQINSTOUT=\n${MQINSTOUT}" ; fi critical_error fi fi print_msg "\n(${MM}/${DD} $(date +%R)) End install_mq" "debug" } ################################################################################ # rollback_mq ################################################################################ rollback_mq() { print_msg "\n(${MM}/${DD} $(date +%R)) Started rollback_mq" "debug" #GVM#unset COUNT MQRPMS QSTRING RESULT RMFILES RMMQRPMS RMMQRPMSOUT RMSERVER unset COUNT _MQRPMSRB QSTRING RESULT RMFILES RMMQRPMS RMMQRPMSOUT RMSERVER unset RPMLIST SVRMINVER UNINSTOUT VERQUERY VERS local COUNT=0 #GVM#local MQRPMS="" local _MQRPMSRB="" local QSTRING="" local RESULT=0 local RMFILES="" local RMMQRPMS="" local RPMCHECKOUT=0 local RPMLIST="" local RMSERVER="${1}" local SVRMINVER=0 local UNINSTOUT="" local VERQUERY="" local VERS="" #GVM#MQRPMS="$( nexec -i -l ${RMSERVER} "${RPM_CMD} -qa | grep -iE \"${RPMBASE}.*_${MQINSTBASE}\" \ # Generate listing of installed RPMs _MQRPMSRB="$( nexec -i -l ${RMSERVER} "${RPM_CMD} -qa | ${GREPNC} -iE \"${RPMBASE}.*_${MQINSTBASE}\" \ | ${GREPNC} -iv \"${MQSERVERRPM}\"" | sed 's/[[:cntrl:]]*//g' )" VERQUERY='s/^${RPMBASE}.*_${MQINSTBASE}\(.*\)${RPMPLATFORM}/\1/g' #GVM#VERS="${MQINSTBASE}${MQVERBASE}${MQVERBASEMIN}" VERS="${MQINSTBASE}${MQVERBASEERE}${MQVERBASEMIN}" #GVM#SVRMINVER="$( echo -e "${MQRPMS}" | grep -iE "${RPMBASE}.*_${MQINSTBASE}" | \ SVRMINVER="$( echo -e "${_MQRPMSRB}" | grep -iE "${RPMBASE}.*_${MQINSTBASE}" | \ grep -vE "(${VERS})" | sed 's/[[:cntrl:]]*//g'| sed -e "${(e)VERQUERY}" | sort -u | \ awk '{print substr($0,length($0),1)}' | head -n 1 )" #GVM#print_msg "\nMQRPMS=${MQRPMS}~nRMSERVER=${RMSERVER}~nSVRMINVER=${SVRMINVER}~n\ print_msg "\n_MQRPMSRB=${_MQRPMSRB}~nRMSERVER=${RMSERVER}~nSVRMINVER=${SVRMINVER}~n\ VERQUERY=${VERQUERY}~nVERS=${VERS}" "debug" # If roll back requested and PATCHVER is not higher than SVRMINVER, cannot roll back # := if SVRMINVER is null or unset, expand to 0 instead if [[ ! ${SVRMINVER:=0} -lt ${PATCHVER} && ${UNINSTALL} != 1 ]] then echo -e "${STARS}\nRollback requested and Patch Version ${PATCHVER} \ is the only removeable version. Run ${NSH} with -U option to uninstall.\n\ ${STARS}" | fold -sw 80 usage fi # Perform Patch Removal or complete uninstall if (( UNINSTALL == 0 )) then #GVM# if [[ ${FPVER} == 0 ]] if [[ ${VER} == 0 ]] then ERRORDESC="ERROR 133: Rollback requested, but no Fix Packs are installed \ on server ${RMSERVER}" let ERROR_CODE=133 critical_error else print_msg "Downgrading MQ Client version ${MQVERBASE}${VER} found at \ ${INSTPATH} on ${RMSERVER}" # Build list of Patch RPMs to remove #GVM# QSTRING="(${MQINSTBASE}${MQUPBASE}${FPVER}-${MQVERBASE}${FPVER})" QSTRING="(${MQINSTBASE}${MQUPBASE}${VER}-${MQVERBASE}${VER})" RMMQRPMS="${RPM_CMD} -ev \$( rpm -qa | ${GREPNC} -E \"${QSTRING}\" | \ sed 's/[[:cntrl:]]*//g' ) 2>&1" COUNT="$( nexec -i -l ${SERVER} "rpm -qa | ${GREPNC} -cE \"${QSTRING}\"" )" if [[ ${COUNT} == 0 ]] then ERRORDESC="ERROR 131: No ${MQVERBASE}${PATCHVER} patches found on ${RMSERVER}" let ERROR_CODE=131 critical_error fi print_msg "\nCOUNT=${COUNT}~nQSTRING=\n${QSTRING}~n\nRMMQRPMS=\n${RMMQRPMS}" "debug" if (( DRYRUN )) then print_msg "\nnexec -i -l ${RMSERVER} \"${RMMQRPMS}\" ; echo -e \"RESULT=\$?\"" "dryrun" else UNINSTOUT="$( nexec -i -l ${RMSERVER} "${RMMQRPMS} ; echo -e \"RESULT=\$?\"" )" let RESULT=$( echo -e "${UNINSTOUT}" | grep "RESULT=" | \ sed 's/[[:cntrl:]]*//g' | cut -f2 -d'=' ) print_msg "\nUNINSTOUT=${UNINSTOUT}~nRESULT=${RESULT}" "debug" if [[ ${RESULT} != 0 ]] then ERRORDESC="ERROR 119: Errors encountered during uninstall/downgrade on ${RMSERVER}" let ERROR_CODE=119 if [[ -n "${UNINSTOUT}" ]] ; then print_msg "UNINSTOUT=\n${UNINSTOUT}" ; fi critical_error else # Set Primary Instance if (( DRYRUN )) then print_msg "\nnexec -i -l ${RMSERVER} \"${SETMQINST}\"" "dryrun" else MQINSTOUT="$( nexec -i -l ${RMSERVER} "${SETMQINST}" )" print_msg "\nMQINSTOUT=\n${MQINSTOUT}" "debug" fi fi fi env_check ${RMSERVER} # Validate that RPMs were uninstalled# if [[ ! ${VER} < ${PATCHVER} ]] then ERRORDESC="ERROR 120: Failed to remove ${MQVERBASE}${PATCHVER} RPMs on ${RMSERVER}" let ERROR_CODE=120 critical_error else # Validate removal and Primary Instance setting if [[ ${EXISTING} != 1 || ${#INSTPATH} == 0 ]] then ERRORDESC="ERROR 121: Failed to set Primary Instance on ${RMSERVER}" let ERROR_CODE=121 if [[ -n "${MQINSTOUT}" ]] ; then print_msg "MQINSTOUT=\n${MQINSTOUT}" ; fi critical_error fi fi fi else # Removing MQ Client install #GVM#print_msg "Removing MQ Client found at ${INSTPATH} on ${RMSERVER}" print_msg "Removing MQ Client version ${MQVERSION} found at ${INSTPATH} on ${RMSERVER}" # -depth instructs find to process the directory contents before the directory RMFILES="${FINDCMD} ${APPPATH:=/usr/mqm} ${DATAPATH:=/var/mqm} /etc/opt/mqm " if (( PTC )) ; then RMFILES+="/opt/mqm " ; fi RMFILES+="-depth -name 'lost+found' -prune -o -path ${APPPATH:=/usr/mqm} " RMFILES+="-prune -o -path ${DATAPATH:=/var/mqm}/app* -prune -o -path ${DATAPATH:=/var/mqm} " RMFILES+="-prune -o -exec /bin/rm -df '{}' \;" QSTRING="${RPMBASE}.*_${MQINSTBASE}.*" COUNT="$( nexec -i -l ${RMSERVER} "rpm -qa | ${GREPNC} -cE \"${QSTRING}\"" | \ sed 's/[[:cntrl:]]*//g' )" if [[ ${COUNT} == 0 ]] then ERRORDESC="ERROR 132: No ${RPMBASE}*_${MQINSTBASE}*.rpm RPMs found on ${RMSERVER}" let ERROR_CODE=132 critical_error fi #GVM# Quiet output or get screens of periods and hashes if (( ! TAGCNT )) then #GVM# fix_install ${RMSERVER} "${_MQRPMSRB}" RMMQRPMS="${RPM_CMD} -ev --allmatches --nodeps --noscripts --notriggers" else RMMQRPMS="${RPM_CMD} -ev --allmatches" fi #GVM# if [ "x${(L)SVROS}" = "xsuse" ] #GVM# then #GVM# # -D --dry-run #GVM# # --no-refresh (global) #GVM# # -n --non-interactive (global) #GVM# # -q --quiet (global) #GVM# # -t --terse (global, implies --no-abbrev and --no-color) #GVM# # -u --clean-deps #GVM# # -v --verbose (global) #GVM# # #GVM#RMMQRPMS="${ZYPPER} -n -q -t --no-refresh rm -u" #GVM# RMMQRPMS="${ZYPPER} -n -t --no-refresh rm -u" #GVM# if (( DRYRUN )) ; then RMMQRPMS+=" --dry-run" ; fi #GVM# fi #GVM# if [ "x${(L)SVROS}" = "xredhat" ] #GVM# then #GVM# # --color=always/never/auto #GVM# # --comment=<comment> #GVM# # -q --quiet #GVM# # --setopt=<option>=<value> tsflags=test -- dry run, no exec #GVM# # -v --verbose #GVM# # -y --assumeyes #GVM# # #GVM# #GVM#RMMQRPMS="${YUM} --color=never --comment=\"Removing MQ Client installation\" -q -y remove" #GVM# RMMQRPMS="${YUM} --color=never --comment=\"Removing MQ Client installation\" -y remove" #GVM# if (( DRYRUN )) ; then RMMQRPMS+=" --setopt=tsflags=test" ; fi #GVM# fi # If variable is unset or null, substitute value to prevent removing all RPMs # sort dictionary-based, field sep '-', 2nd field, reverse order #GVM# RMMQRPMS="${RPM_CMD} -ev --allmatches \$( rpm -qa | grep -iE \"${QSTRING:=\"_none_\"}\" ) 2>&1" if [[ ${#RMMQRPMS} == 0 ]] then ERRORDESC="ERROR 138: Failed to set package manager for ${RMSERVER}" let ERROR_CODE=138 critical_error else RMMQRPMS+=" \$( rpm -qa | ${GREPNC} -iE \"${QSTRING:=\"_none_\"}\" | \ sed 's/[[:cntrl:]]*//g' | sort -dt '-' -k 2r ) 2>/tmp/mquninstall.log" RMMQRPMS+=" ; let RESULT=\$? ; if [[ \${RESULT} == 0 ]] ; then ${RMFILES}" RMMQRPMS+=" ; else echo \"RMMQFAILED\" ; fi" fi print_msg "QSTRING=${QSTRING}~n\nRMMQRPMS=${RMMQRPMS}" "debug" if (( DRYRUN )) then print_msg "\nnexec -i -l ${RMSERVER} \"${RMMQRPMS}\"" "dryrun" else UNINSTOUT="$( nexec -i -l ${RMSERVER} "${RMMQRPMS}" )" let RPMCHECKOUT="$( echo -e "${UNINSTOUT}" | grep -ic "RMMQFAILED" )" print_msg "\nUNINSTOUT=\n${UNINSTOUT}~nRESULT=${RESULT}~nRPMCHECKOUT=\ ${RPMCHECKOUT}" "debug" if [[ ${RPMCHECKOUT} != 0 ]] then ERRORDESC="ERROR 122: Failed to remove all MQ RPMs on ${RMSERVER}" let ERROR_CODE=122 if [[ -n "${UNINSTOUT}" ]] ; then print_msg "UNINSTOUT=\n${UNINSTOUT}" ; fi critical_error fi fi fi print_msg "\n(${MM}/${DD} $(date +%R)) End rollback_mq" "debug" }
-
@Michael-Vincent Part 5
################################################################################ # ptc_symlink ################################################################################ ptc_symlink() { print_msg "\n(${MM}/${DD} $(date +%R)) Started ptc_symlink" "debug" unset BASELINKCMD DELLINKCHK DSSVR LINKCHK LINKCMDOUT local BASELINKCMD="${(e)LINKCMD}" local DELLINKCHK="" local DSSVR="${1}" local LINKCHK="" local LINKCMDOUT="" # Check for existence of /opt/mqm symbolic link to /usr/mqm/MQCV LINKCHK="$( find //${DSSVR}/opt -maxdepth 1 -type l -ls 2>/dev/null | grep -icE 'lrwx.*mqm[ \t]*->' )" print_msg "BASELINKCMD=${(e)BASELINKCMD}~nLINKCHK=${LINKCHK}~nOPTDIR=${OPTDIR}~n\ UNINSTALL=${UNINSTALL}" "debug" if [[ ${UNINSTALL} == 1 && ${LINKCHK} == 1 ]] then # Uninstalling - remove symbolic link BASELINKCMD='find /opt -maxdepth 1 -type l -ilname '*mqm*' -exec /bin/rm -vf {} \;' if (( DRYRUN )) then print_msg "\nnexec -i -l ${DSSVR} \"${(e)BASELINKCMD}\"" "dryrun" else LINKCMDOUT="$( nexec -i -l ${DSSVR} ${(e)BASELINKCMD} )" print_msg "BASELINKCMD=${(e)BASELINKCMD}~nLINKCMDOUT=${LINKCMDOUT}" "debug" DELLINKCHK="$( ${LINKCHK} | grep -icE '^l.*mqm ->' )" if [[ ${DELLINKCHK} != 0 ]] then ERRORDESC="ERROR 125: Failed to remove /opt/mqm symbolic link on ${DSSVR}" let ERROR_CODE=125 if [[ -n "${LINKCMDOUT}" ]] ; then print_msg "LINKCMDOUT=\n${LINKCMDOUT}" ; fi critical_error fi fi elif [[ ${UNINSTALL} == 0 ]] then if [[ ${OPTDIR} == 1 ]] then # Force uninstallation of PTC MQ Client from /opt/mqm export UNINSTALL=1 rollback_mq ${DSSVR} # Reset UNINSTALL and OPTDIR values export UNINSTALL=0 export OPTDIR=0 # Create symbolic link for /opt/mqm -> /usr/mqm/MQCV ptc_symlink ${DSSVR} # Reset environment checks env_check ${DSSVR} elif [[ ${LINKCHK} == 0 ]] then print_msg "Symbolic link not found in /opt/mqm on ${DSSVR} - creating it" unset LINKCHK if (( DRYRUN )) then print_msg "\nnexec -i -l ${DSSVR} \"${(e)BASELINKCMD} ; sleep 5\"" "dryrun" else LINKCMDOUT="$( nexec -i -l ${DSSVR} "${(e)BASELINKCMD} 2>/dev/null \ ; echo -e \"RESULT=\$?\" ; sleep 5 ; ${FINDCMD} /opt -maxdepth 1 -type l -ilname '*mqm*' -ls 2>/dev/null" )" let LINKCHK="$( find //${DSSVR}/opt -maxdepth 1 -type l -ls 2>/dev/null | \ grep -icE 'l[wrx]{3}.*mqm ->' )" print_msg "BASELINKCMD=${(e)BASELINKCMD}~nLINKCHK=${LINKCHK}~n\ LINKCMDOUT=${LINKCMDOUT}" "debug" if [[ ${LINKCHK} == 0 ]] then ERRORDESC="ERROR 124: Failed to create /opt/mqm symbolic link on ${DSSVR}" let ERROR_CODE=124 if [[ -n "${LINKCMDOUT}" ]] ; then print_msg "LINKCMDOUT=\n${LINKCMDOUT}" ; fi critical_error fi fi fi fi print_msg "\n(${MM}/${DD} $(date +%R)) End ptc_symlink" "debug" } ################################################################################ # fix_install ################################################################################ fix_install() { print_msg "\n(${MM}/${DD} $(date +%R)) Started fix_install" "debug" unset FIXFILE FIXRPMS FIXRPMSBASE FIXRPMSFP FIXSVR MQFIXCMD MQFIXCMDOUT local FIXFILE="${MQINSTBASE}${MQVERSION}.tar.gz" local FIXRPMS="${2}" local FIXRPMSBASE="" local FIXRPMSFP="" local FIXSVR="${1}" local MQFIXCMD="" local let MQFIXCMDOUT=99 FIXRPMS="$( for rpm in $(echo -e "${FIXRPMS}") ; do echo -n "${rpm}${RPMSUFFIX} " ; done )" #GVM#FIXRPMSBASE="$( echo -e "${FIXRPMS}" | grep -ivE "(BES|${MQVERBASEERE}[^0])" | tr -s '\n' ' ' )" #GVM#FIXRPMSFP="$( echo -e "${FIXRPMS}" | grep -ivE "(BES|${MQVERBASEERE}0)" | tr -s '\n' ' ' )" FIXRPMSBASE="$( for rpm in $( echo -e "${FIXRPMS}" ) ; do echo -n "${DATAPATH}/MQCV/${rpm}" | \ grep -ivE "(BES|${MQVERBASEERE}[^0])" ; done )" FIXRPMSBASE="$( echo -e "${FIXRPMSBASE}" | tr '\n' ' ' )" FIXRPMSFP="$( for rpm in $( echo -e "${FIXRPMS}" ) ; do echo -n "${DATAPATH}/MQCV/${rpm}" | \ grep -ivE "(BES|${MQVERBASEERE}0)" ; done )" FIXRPMSFP="$( echo -e "${FIXRPMSFP}" | tr '\n' ' ' )" MQFIXCMD="${RPMINST} --force ${FIXRPMSFP} 2>&1 ; echo -e \"RESULT=\$?\"" print_msg "FIXFILE=${FIXFILE}~n\nFIXRPMS=${FIXRPMS}~n\nFIXRPMSBASE=${FIXRPMSBASE}~n\ \nFIXRPMSFP=${FIXRPMSFP}~nFIXSVR=${FIXSVR}~n\nMQFIXCMD=${MQFIXCMD}~nMQFIXCMD=${MQFIXCMD}" "debug" if (( DRYRUN )) then print_msg "copy_files ${FIXSVR} ${SOURCESVR} \"${(e)SOURCEDIR}${PATCHVER}\" \"${FIXFILE}\"" "dryrun" print_msg "MQFIXCMDOUT=\"\$( nexec -i -l ${FIXSVR} \"${MQFIXCMD}\" )\"" "dryrun" else copy_files ${FIXSVR} ${SOURCESVR} "${(e)SOURCEDIR}${PATCHVER}" "${FIXFILE}" MQFIXCMDOUT="$( nexec -i -l ${FIXSVR} "${MQFIXCMD}" )" print_msg "\nMQFIXCMDOUT=${MQFIXCMDOUT}" "debug" if [[ $( echo -e "${MQFIXCMDOUT}" | grep -i "RESULT=" | \ sed 's/[[:cntrl:]]*//g' | cut -f2 -d'=' ) != 0 ]] then ERRORDESC="ERROR 140: Errors detected after fixing install on ${FIXSVR}" let ERROR_CODE=140 if [[ -n "${MQFIXCMDOUT}" ]] ; then print_msg "MQFIXCMDOUT=\n${MQFIXCMDOUT}" ; fi critical_error fi fi print_msg "\n(${MM}/${DD} $(date +%R)) End fix_install" "debug" } ################################################################################ # Main ################################################################################ # Check for log path. Create if not found. if [[ -d '/tmp' ]] then export LOGPATH='/tmp' elif [[ -d '/C/Temp' ]] then export LOGPATH='/C/Temp' fi if [[ ! -d "${LOGPATH}" ]] ; then mkdir -p "${LOGPATH}" ; fi # Files LOGFILE="${LOGPATH}/${NSH}.${MMDD}" MAILFILE="${LOGPATH}/${NSH}.mail" TMPLOG="${LOGPATH}/${NSH}.$$.${MMDD}${YYYY}${HH}${MIN}.log" # Clean up prior log file if [[ -f ${TMPLOG} ]] ; then rm -f ${TMPLOG} ; fi print_msg "\n(${MM}/${DD} $(date +%R)) Started ${NSH}" # Validate number of arguments given if [[ ! $# -ge 2 ]] ; then let ERROR_CODE=0 ; usage ; fi # leading ':' enables quiet processing with '?' and ':' as values when problems # are encountered. # trailing ':' indicates that an option requires an argument. while getopts ":dhp:Rs:Uy" OPT do case "${OPT}" in d|D) # Enable DEBUG let DEBUG=1 print_msg "DEBUG MODE ENABLED" print_msg "DEBUG=${DEBUG}" "debug" ;; h|H) # Help/usage usage ;; p|P) # Patch version to install if [[ $( awk -v num=${OPTARG} 'BEGIN {if (num ~ /[0-9]+/) { print "1" }}' ) == 1 ]] then let PATCHVER=${OPTARG} print_msg "PATCHVER=${PATCHVER}" "debug" else ERRORDESC="ERROR 100: Unrecognized Patch Version: ${OPTARG}" let ERROR_CODE=100 critical_error fi ;; R) # Rollback/uninstall MQ Client let ROLLBACK=1 print_msg "ROLLBACK PROCESSING" print_msg "ROLLBACK=${ROLLBACK}" "debug" ;; s|S) # Host list HOSTS="${OPTARG}" if [[ $( echo -e "${HOSTS}" | awk '{if ($0 ~ /(,|;|:|\t)/) {print "1"} else {print "0"}}' ) -ge 1 ]] then HOSTS="$( echo -e "${HOSTS}" | tr -s ',:;\t' ' ' )" fi print_msg "HOSTS=${HOSTS}" "debug" ;; U) # Uninstall MQ Client let UNINSTALL=1 print_msg "UNINSTALL PROCESSING" print_msg "UNINSTALL=${UNINSTALL}" "debug" ;; y|Y) # Enable DRYRUN let DRYRUN=1 print_msg "Executing DRYRUN" print_msg "DRYRUN=${DRYRUN}" "debug" ;; \?) # Invalid option print_msg "Invalid option ${OPTARG} provided" usage ;; \:) # Missing required argument to option print_msg "Option ${OPTARG} requires an argument." usage ;; esac done # remove processed options leaving what remains as $@ shift $(( OPTIND - 1 )) if [[ -n "$@" ]] ; then print_msg "\$@=$@" "debug" ; fi # ROLLBACK and UNINSTALL are mutually exclusive if [[ ${UNINSTALL} == 1 && ${ROLLBACK} == 1 ]] then print_msg "Rollback and Uninstall options are mutually exclusive" usage fi # Check for tarball on source server # (e) Perform parameter expansion, command substitution and arithmetic expansion # on the result. # # Expected tar file name format: MQCV-9.2.0-X.tar.gz # TARBALL="$( ls //${SOURCESVR}${SOURCEPATH} 2>/dev/null | \ grep -iE "${(e)SOURCEFILES}" | sed 's/[[:cntrl:]]*//g' | sort -d )" TARNUM=$( echo -e "${TARBALL}" | grep -icE "${(e)SOURCEFILES}" ) #GVM#print_msg "\nTARBALL=\n$( echo -e "${TARBALL}" | sed 's/\(^.*$\)/\\t\1/g' )\ #GVM#~nTARNUM=${TARNUM}" "debug" print_msg "~nTARBALL=\n$( echo -e "${TARBALL}" | sed 's/\(^.*$\)/\\t\1/g' )\ ~nTARNUM=${TARNUM}" "debug" # If PATCHVER is not passed in as an argument, determine most recent patch level # based on tarball name on source server if [[ ${TARNUM} -ge 1 && ${PATCHVER} == 0 ]] then let PATCHVER="$( echo -e "${TARBALL}" | tail -n 1 | awk '{ print substr($0,index($0,".tar.gz")-1,1) }' )" print_msg "PATCHVER=${PATCHVER}" "debug" fi # Validate PATCHVER is set and use it to set TARFILE if [[ ${PATCHVER} == 0 ]] then ERRORDESC="ERROR 101: Failed to set Patch Version" let ERROR_CODE=101 critical_error else #GVM# TARFILE="$( echo -e "${TARBALL}" | grep -iE "${MQVERBASE}${PATCHVER}" )" #GVM# TARFILE="$( echo -e "${TARBALL}" | grep -iE "${MQVERBASEERE}${PATCHVER}" )" TARFILE="$( echo -e "${TARBALL}" | \ grep -iE "${MQVERBASEERE}${PATCHVER}" | sed 's/[[:cntrl:]]*//g' | tail -n 1 )" #GVM# print_msg "TARFILE=${TARFILE}" "debug" if [[ ! -n ${TARFILE} ]] then ERRORDESC="ERROR 102: Failed to set TARFILE" let ERROR_CODE=102 critical_error else # (e) expand variable first # #*- strip off all characters up to and including the first '-' # /.tar.gz search and remove '.tar.gz' # %-* print all characters up to and including the first '-' # starts with MQCV-9.3.0-4.tar.gz # ends with 9.3.0- MQVERBASE="$( echo -e "${${${(e)TARFILE#*-}/.tar.gz}%-*}-" )" # strip all '.' and '-' characters typeset -i BASECMDLVL=$( echo -e "${MQVERBASE}" | tr -d '.-' ) MQUPBASE="U$( echo -e "${BASECMDLVL}" )" print_msg "TARFILE=${TARFILE}~nBASECMDLVL=${BASECMDLVL}~nMQUPBASE=${MQUPBASE}\ ~nMQVERBASE=${MQVERBASE}" "debug" fi fi # Build RPM lists if (( ! UNINSTALL )) then for rpm in ${MQRPMS} do RPMINSTLIST+="${DATAPATH}/MQCV/${rpm}${MQINSTBASE}${MQVERBASE}${MQVERBASEMIN}${RPMPLATFORM}\ ${RPMSUFFIX} " RPMUPLIST+="${DATAPATH}/MQCV/${rpm}${MQINSTBASE}${MQUPBASE}${PATCHVER}-\ ${MQVERBASE}${PATCHVER}${RPMPLATFORM}${RPMSUFFIX} " done print_msg "\nRPMINSTLIST=${RPMINSTLIST}~n\nRPMUPLIST=${RPMUPLIST}" "debug" fi # Process hosts list one server at a time for host in ${HOSTS} do print_msg "Processing ${host}" # Validate environment env_check ${host} # If uninstalling or rolling back if (( ROLLBACK || UNINSTALL )) then # If no install is found if [[ ${EXISTING} == 0 && ${NEWINST} == 0 ]] then print_msg "No installations of MQ Client found on ${host}" # Verify requested version to rollback matches installed version #GVM# elif (( PATCHVER < VER && MAJVER >= 9 )) elif [[ ${BASECMDLVL}${PATCHVER} < ${MAXCMDLVL}${VER} && ${MAJVER} -ge 9 ]] then ERRORDESC="ERROR 103: Requested version to rollback \ \"${MQVERBASE}${PATCHVER}\" is below installed version \"${MQVERBASE}${VER}\"" let ERROR_CODE=103 critical_error else # Perform rollback on host rollback_mq ${host} fi # If host is already running requested patch version #GVM# elif [[ ${PATCHVER} == ${VER} ]] elif [[ ${BASECMDLVL}${PATCHVER} == ${MAXCMDLVL}${VER} ]] then print_msg "${host} is already running version ${MQVERBASE}${PATCHVER}" if (( BESINSTALL )) ; then install_bes ${host} ; fi else # Install or apply Fix Pack # Create /opt/mqm symbolic link for PTC environment if (( PTC )) ; then ptc_symlink ${host} ; fi # Copy files to target # Avoid copying files twice if BASECMDLVL > MAXCMDLVL (9.3.0 > 9.2.0) #GVM# if [[ ${ROLLBACK} == 0 && ${UNINSTALL} == 0 ]] if [[ ${ROLLBACK} == 0 && ${UNINSTALL} == 0 && ${BASECMDLVL} > ${MAXCMDLVL} ]] then #GVM# copy_files ${host} ${SOURCESVR} "${SOURCEDIR}${PATCHVER}" "${TARFILE}" copy_files ${host} ${SOURCESVR} "${(e)SOURCEDIR}${PATCHVER}" "${TARFILE}" fi # Install BESAgent if not installed if (( BESINSTALL )) ; then install_bes ${host} ; fi #GVM# if (( NEWINST )) if [[ ${NEWINST} == 1 || ${MAXCMDLVL} < ${BASECMDLVL} ]] then # New install install_mq ${host} "${RPMINSTLIST}" else # Fix Pack install install_mq ${host} "${RPMUPLIST}" fi # Clean up RPMs and tarballs # ':=' If unset or null, set DATAPATH to /var/mqm to prevent any possibility # of acting on files in the / file system if (( DRYRUN )) then #GVM# print_msg "\nnexec -i -l ${host} \"/bin/rm -dfR \ #GVM#${DATAPATH:=/var/mqm}/MQCV ; /bin/rm -dfR ${DATAPATH:=/var/mqm}/BESClient\"" "dryrun" print_msg "\nnexec -i -l ${host} \"/bin/rm -dfR \ ${DATAPATH:=/var/mqm}/MQCV ; /bin/rm -f ${DATAPATH:=/var/mqm}/MQCV-*.*.*-*.tar.gz ; \ /bin/rm -dfR ${DATAPATH:=/var/mqm}/BESClient\"" "dryrun" else #GVM# nexec -i -l ${host} "/bin/rm -dfR ${DATAPATH:=/var/mqm}/MQCV ; \ #GVM#/bin/rm -dfR ${DATAPATH:=/var/mqm}/BESClient" #GVM# nexec -i -l ${host} "/bin/rm -dfR ${DATAPATH:=/var/mqm}/MQCV ; \ #GVM#/bin/rm -f ${DATAPATH:=/var/mqm}/MQCV-*.*.*-*.tar.gz ; /bin/rm -dfR ${DATAPATH:=/var/mqm}/BESClient" nexec -i -l ${host} "${(e)CLEANCMD}" fi fi # Skip copying log file for dry run if (( ! DRYRUN )) then if (( UNINSTALL )) then cp ${TMPLOG} //${host}${MQCVPATH}/${NSH}.${MMDD}${YYYY}${HH}${MIN}.uninstall.log else cp ${TMPLOG} //${host}${MQCVPATH}/${NSH}.${MMDD}${YYYY}${HH}${MIN}.log fi fi done print_msg "\n(${MM}/${DD} $(date +%R)) Finished ${NSH}" #------------------------------------------------------------------------------- # Retention is listed below at 90 days for logs and datafiles. Ask user of # process for actual retention specifications and change accordingly. #------------------------------------------------------------------------------- CURRDIR="${PWD}" cd "${LOGPATH}" find -path "${LOGPATH}" \( -name ${NSH}'.*.log' -o -name 'delete.*' \) -mtime +90 \ -exec /bin/rm -f {} \; 2>>${LOGPATH}/delete.${MMDD} cd "${CURRDIR}" # Process log files and exit critical_error #END
-
I think something went wrong with the cut and pastes, from line 403 on it lexes as a string:
-
The following two lines in the
ptc_symlink
-function are the problem:LINKCMDOUT="$( nexec -i -l ${DSSVR} "${(e)BASELINKCMD} 2>/dev/null \ ; echo -e \"RESULT=\$?\" ; sleep 5 ; ${FINDCMD} /opt -maxdepth 1 -type l -ilname '*mqm*' -ls 2>/dev/null" )"
When you escape two additional double-quotes, refresh or save the file, the
fix_install
-function is listed
e.g.LINKCMDOUT="$( nexec -i -l ${DSSVR} \"${(e)BASELINKCMD} 2>/dev/null \ ; echo -e \"RESULT=\$?\" ; sleep 5 ; ${FINDCMD} /opt -maxdepth 1 -type l -ilname '*mqm*' -ls 2>/dev/null\" )"
-
@MAPJe71 Interesting… I have a few other lines throughout the script that utilize the same syntax structure I believe. Why wouldn’t those functions be affected the same way? For example, lines #370-#375, lines #814-#815, lines #1271-#1272, line #1321, line #1333, and lines #1384-#1385.
For what it’s worth, I’ll explain what the line is doing from an application perspective.
This script runs in BMC’s TrueSight Server Automation as an NSH script. NSH is based on the ZShell. The syntax of the command is such that the subshell command “nexec” is doing a remote shell execution on a target server to create a symbolic link, echo the result with a “RESULT=” prefix, waits 5 seconds, and then does a find command to list out the contents of the /opt path looking for symbolic links.
The output looks similar to this:
RESULT=0 nexec -i -l algebs.ds.cpr.ca "/bin/find /opt -type l -ilname '*mqm*' -ls" 867 0 lrwxrwxrwx 1 mqm mqm 21 Nov 9 2021 /opt/mqm/bin -> /usr/mqm/MQSV9202/bin
Thanks!
-
@Michael-Vincent said in Function List incomplete:
I think something went wrong with the cut and pastes, from line 403 on it lexes as a string:
I went back and copied that section of pasted code separately from the forum post into a new Shell-formatted document in NP++ and it looked normal. Did you possibly miss a starting quote in the copy/paste from the forum into your NP++?