#!/bin/bash TSM_SERVER="tsmsrv" TSM_ADMIN="user" TSM_PASSW="passw" LOG_FILE="/var/log/tsm_auto_deploy_planner.log" RESULT_CHECK_FILE="/var/log/tsm_auto_deploy_planner.check" TMP_FILE="/tmp/tsm_auto_deploy_planner.rc.tmp" # AZ EZ ALATTI KODOT NE PISZKALD, CSAK HA TUDOD MIT CSINALSZ SQL_Q_DEPLOY_PACKAGES="SELECT DISTINCT(DESCRIPTION),NODE_NAME,FILESPACE_NAME,HL_NAME,LL_NAME FROM ARCHIVES WHERE NODE_NAME LIKE 'IBM_CLIENT_DEPLOY%' and TYPE='FILE' and ( LL_NAME='DEPLOYCLIENT.BAT' OR LOWER(LL_NAME)='deployclient.sh' ) and DESCRIPTION LIKE 'DEPLOY%'" SQL_QUERY_DEPLOY_DIR="SELECT DIRECTORY FROM DEVCLASSES WHERE DEVCLASS_NAME IN (SELECT DEVCLASS FROM STGPOOLS WHERE STGPOOL_NAME IN (SELECT DESTINATION FROM AR_COPYGROUPS WHERE DOMAIN_NAME='IBM_CLIENT_DEPLOY' AND SET_NAME='ACTIVE'))" SQL_DEPLOYED_NODES="SELECT DISTINCT substr(N.NODE_NAME,1,22) as \"NODE\", substr(CS.SCHEDULE_NAME,1,22) as \"SCHEDULE\", substr(N.CLIENT_VERSION || '.' || N.CLIENT_RELEASE || '.' || N.CLIENT_LEVEL || '.' || N.CLIENT_SUBLEVEL || ' - ' || N.CLIENT_TARGET_VERSION || '.' || N.CLIENT_TARGET_RELEASE || '.' || N.CLIENT_TARGET_LEVEL || '.' || N.CLIENT_TARGET_SUBLEVEL,1,18) as \"CLIENT - TARGET\", case when N.CLIENT_VERSION || '.' || N.CLIENT_RELEASE || '.' || N.CLIENT_LEVEL || '.' || N.CLIENT_SUBLEVEL != N.CLIENT_TARGET_VERSION || '.' || N.CLIENT_TARGET_RELEASE || '.' || N.CLIENT_TARGET_LEVEL || '.' || N.CLIENT_TARGET_SUBLEVEL then '!!' else 'OK' end as \"OK\", substr(N.PLATFORM_NAME,1,15) as \"OS_VERSION\" FROM NODES N, ASSOCIATIONS A, CLIENT_SCHEDULES CS WHERE N.NODE_NAME=A.NODE_NAME AND A.SCHEDULE_NAME=CS.SCHEDULE_NAME AND CS.ACTION='DEPLOY'" DSMADMC="dsmadmc -id=$TSM_ADMIN -pa=$TSM_PASSW -se=$TSM_SERVER -dataonly=y " red=$'\e[1;31m' grn=$'\e[1;32m' yel=$'\e[1;33m' blu=$'\e[1;34m' mag=$'\e[1;35m' cyn=$'\e[1;36m' whi=$'\e[1;37m' inv=$'\e[7;37m' gry=$'\e[1;90m' end=$'\e[0m' clear # FEJLECT MEGRAJZOLASA FEJLEC="TSM Auto Deployment planner v1.3 (2015.09.24.)" FEJLEC2="written by Peter Agoston" printf "${inv}" J=0 for I in $(seq 1 $(tput cols)); do printf "#"; done; #printf "\n" for I in $(seq 1 $(tput cols)); do printf " "; done; #printf "\n" for I in $(seq 1 $(($(tput cols)/2-${#FEJLEC}/2-${#FEJLEC}%2))); do printf " "; J=$(($J+1)); done; printf "$FEJLEC"; for I in $(seq 1 $(($(tput cols)/2-${#FEJLEC}/2))); do printf " "; J=$(($J+1)); done; if [[ $(($J + ${#FEJLEC})) -lt $(tput cols) ]]; then printf " "; fi #printf "\n" J=0 for I in $(seq 1 $(($(tput cols)/2-${#FEJLEC2}/2-${#FEJLEC2}%2))); do printf " "; J=$(($J+1)); done; printf "$FEJLEC2"; for I in $(seq 1 $(($(tput cols)/2-${#FEJLEC2}/2))); do printf " "; J=$(($J+1)); done; if [[ $(($J + ${#FEJLEC2})) -lt $(tput cols) ]]; then printf " "; fi #printf "\n" for I in $(seq 1 $(tput cols)); do printf " "; done; #printf "\n" for I in $(seq 1 $(tput cols)); do printf "#"; done; #printf "\n" printf "${end}\n" # FEJLEC VEGE printf "Szabalyrendszer lekerdezese... a telepito keszletek tarolasi utvonala: " DEPLOYDIR=$($DSMADMC -displ=tab "$SQL_QUERY_DEPLOY_DIR") if [[ $? -ne 0 ]]; then printf "${red}\nNem sikerult lekerdezni, valoszinuleg nem letezik a szukseges Domain es a Stgpool. Ez problema lehet...\n\n${end}" else DEPLOYDIR=${DEPLOYDIR%% *} printf "${gry}${DEPLOYDIR##DIRECTORY: }${end}\n\n" fi printf "${whi}A TSM szerverre beimportalt telepito keszletek:\n" printf "## VERSION PLATFORM ARCHITECTURE${gry}\n" I=0 while read -r SOR; do I=$(($I+1)) PACKAGE=$(echo $SOR | awk -F, '{print $1}') PACK_NODE[$I]=$(echo $SOR | awk -F, '{print $2}') FILESPACE[$I]=$(echo $SOR | awk -F, '{print $3}') HL_NAME[$I]=$(echo $SOR | awk -F, '{print $4}') LL_NAME[$I]=$(echo $SOR | awk -F, '{print $5}') VERSION[$I]=$(echo $PACKAGE | awk -F' ' '{print $2}') PLATFORM[$I]=$(echo $PACKAGE | awk -F' ' '{print $3}') ARCHITECTURE[$I]=$(echo $PACKAGE | awk -F' ' '{print $4}') if [[ "${PLATFORM[$I]}" = "Windows" ]]; then ARCHITECTURE[$I]=$(echo $PACKAGE | awk -F' ' '{print $4}' | sed 's/X32/x86/'); fi echo "$I $PACKAGE" | awk -F' ' '{printf "%2s %-9s %-10s %-12s\n",$1,$3,$4,$5}' done <<< "`$DSMADMC -commadel -displ=tabl "$SQL_Q_DEPLOY_PACKAGES"`" echo printf " i Uj telepitokeszlet beimportalasa a szerverre (.exp)\n" printf " e Auto Deployra jelolt node-ek kliens verzioinak ellenorzese\n" printf " f Auto Deployra jelolt node-ek kliens verzioinak ellenorzese (csak sikerteleneket mutat)\n" printf " d Auto Deploy kliens üzenetek keresése node-hoz az activity logban.\n" printf " h Segitseg a hasznalathoz\n" printf " q Kilepes\n" echo # Program fo ciklus eleje #while [[ $DEPL_PACK_ID -le 0 || $DEPL_PACK_ID -gt $I ]]; do while [[ $DEPL_PACK_ID != "q" ]]; do printf "${whi}Add meg a hasznalni kivant telepito keszlet sorszamat, vagy a funkcio betujelet: ${end}" read DEPL_PACK_ID echo >> $LOG_FILE date >> $LOG_FILE echo "Valasztott menupont: $DEPL_PACK_ID" >> $LOG_FILE # HELP if [[ $DEPL_PACK_ID = "h" ]]; then cat << HELP ${end}A Client Autodeploy hasznalatahoz szukseges letrehozni nehany elemet a TSM szabalyrendszerben, amik az autodeploy csomagok tarolasahoz szuksegesek. Ezek az alabbiak: /* A ${red}pirossal${end} jelolteket muszaj a helyi sajatossagoknak megfeleloen beallitani, a ${yel}sargakat${end} opcionalisan lehet modositani */ /* ide fogjuk elhelyezni az FTP-rol letoltott .exp fajlokat, amit az import majd hasznal */ ${gry}DEFINE DEVCLASS ${yel}DEPLOY_IMPORT${end} DEVTYPE=FILE DIRECTORY="${red}/sanfs/autodeploy${gry}"${end} /* ezen a file devclass-on definialt volume-okon fogja tarolni a TSM szerver az importalt, kliensekre teritendo kodot */ ${gry}DEFINE DEVCLASS ${yel}DEPLOY_DATA${end} DEVTYPE=FILE DIRECTORY="${red}/sanfs/autodeploy${gry}"${end} ${gry}DEFINE STGPOOL ${yel}autodep DEPLOY_DATA${end} MAXSCRATCH=${yel}100${end} /* Kulon policy domaint es szabalyrendszert keszit hozza, de latva a műkodesi elvet, ez nem feltetlenul szukseges! */ ${gry}DEFINE DOMAIN ${yel}IBM_CLIENT_DEPLOY${end} DEFINE POLICYSET ${yel}IBM_CLIENT_DEPLOY IBM_CLIENT_DEPLOY${end} DEFINE MGMTCLASS ${yel}IBM_CLIENT_DEPLOY IBM_CLIENT_DEPLOY IBM_CLIENT_DEPLOY${end} DEFINE COPYGROUP ${yel}IBM_CLIENT_DEPLOY IBM_CLIENT_DEPLOY IBM_CLIENT_DEPLOY${end} STANDARD TYPE=ARCHIVE DESTINATION=${yel}autodep${end} RETVER=${yel}1826${gry} ASSIGN DEFMGMTCLASS ${yel}IBM_CLIENT_DEPLOY IBM_CLIENT_DEPLOY IBM_CLIENT_DEPLOY${end} ACTIVATE POLICYSET ${yel}IBM_CLIENT_DEPLOY IBM_CLIENT_DEPLOY${end} /* IBM FTP autodeploy-bol letoltott .exp (TSM export) formatumú telepitokeszlet importalasa a TSM szerverre (a DEPLOY_IMPORT devclass konyvtarabol) */ ${gry} IMPORT NODE * FILEDATA=ARCHIVE MERGEFILESPACE=YES REPLACE=ALL DEVCLASS=${yel}DEPLOY_IMPORT${end} VOLUMENAMES=${red}6.2.2.0-TIV-TSMBAC-WinX32.exp${end} HELP # HIBAKERESES FUNKCIO elif [[ $DEPL_PACK_ID = "d" ]]; then printf "${whi}Meilyik node-ot nyomozzuk? ${end}" read NODE_TO_DEBUG $DSMADMC "select date_time, message from actlog where (date_time \> current_timestamp - 168 hours) and msgno in (4263,4264,4242,4212,4274,4210,4213,4220,4215,4260,4259,4273,4276,4271,4243,4206,4253,4298) and nodename=upper('$NODE_TO_DEBUG') order by date_time desc" echo # ELLENORZES FUNKCIO elif [[ $DEPL_PACK_ID = "e" ]]; then printf "${red}" > $RESULT_CHECK_FILE date >> $RESULT_CHECK_FILE printf "${whi}NODE SCHEDULE CLIENT - TARGET C=T OS_VERSION\n" | tee -a $RESULT_CHECK_FILE printf "${whi}----------------------- ----------------------- ------------------- --- ------------${gry}\n" | tee -a $RESULT_CHECK_FILE $DSMADMC "$SQL_DEPLOYED_NODES" | sed "s/!!/${red}!!${gry}/" | tee -a $RESULT_CHECK_FILE printf "${end}\n" | tee -a $RESULT_CHECK_FILE echo "A listat ebbe a fajlba is kiirtam: $RESULT_CHECK_FILE" echo # ELLENORZES FUNKCIO (CSAK SIKERTELENEK) elif [[ $DEPL_PACK_ID = "e" ]]; then printf "${red}" > $RESULT_CHECK_FILE date >> $RESULT_CHECK_FILE printf "${whi}NODE SCHEDULE CLIENT - TARGET C=T OS_VERSION\n" | tee -a $RESULT_CHECK_FILE printf "${whi}----------------------- ----------------------- ------------------- --- ------------${gry}\n" | tee -a $RESULT_CHECK_FILE $DSMADMC "$SQL_DEPLOYED_NODES" | grep '!!' | sed "s/!!/${red}!!${gry}/" | tee -a $RESULT_CHECK_FILE printf "${end}\n" | tee -a $RESULT_CHECK_FILE echo "A listat ebbe a fajlba is kiirtam: $RESULT_CHECK_FILE" echo # UJ TELEPITOKESZLET IMPORTALASA elif [[ $DEPL_PACK_ID = "i" ]]; then printf "${whi}Add meg az importalni kivant telepito keszlet fajlnevet, amit mar felmasoltal a ${DEPLOYDIR##DIRECTORY: } konyvtarba (pl: 7.1.1.4-TIV-TSMBAC-LinuxX86.exp): ${end}" read IMPORT_PACK_FNAME [[ "$IMPORT_PACK_FNAME" =~ \.exp$ ]] && $DSMADMC -displ=tab "IMPORT NODE * FILEDATA=ARCHIVE REPLACE=ALL MERGEFILESPACE=YES DEVCLASS=DEPLOY_IMPORT VOLUMENAMES=$IMPORT_PACK_FNAME" | tee -a $LOG_FILE && echo "Kellhet par perc, mig az import lefut a hatterben." # KILEPES A PROGRAMBOL elif [[ $DEPL_PACK_ID = "q" ]]; then exit 0 elif [[ $DEPL_PACK_ID =~ [0-9]+ ]]; then # DEPLOY FUNKCIO printf "${whi}Mi legyen a letrehozando utemezes neve? ${end}" read DEPL_SCH_NAME printf "${whi}Mi a node(ok) neve, amin upgrade-elni szeretned a klienst? (Ha tobb van, szokozzel elvalasztva sorold fel oket.)${end}\n" read DEPL_NODE_NAME STARTDATE="-" until [[ $STARTDATE =~ [01][0-9]/[0-3][0-9]/201[5-9] || -z $STARTDATE ]]; do printf "${whi}Az utemezes indulasanak datuma (HH/NN/EEEE): ${end}" read STARTDATE done STARTDATE=${STARTDATE:=$(date "+%m/%d/%Y")} STARTTIME="-" until [[ $STARTTIME =~ [012][0-9]:[0-5][0-9] ]]; do printf "${whi}Az utemezes indulasanak ideje (OO:PP): ${end}" read STARTTIME done echo for NODE in $DEPL_NODE_NAME; do echo "${yel}#### $NODE ####${end}" DEPL_DOM_NAME=$($DSMADMC "select domain_name from nodes where node_name=upper('${NODE}')" | sed 's/ //g') if [[ $(echo $DEPL_DOM_NAME) =~ ^ANR[0-9]{4} ]]; then printf "${red}Ilyen node talan nincs. Ellenorizd!${end}\n\n"; continue; fi case "${PLATFORM[$DEPL_PACK_ID]}" in Windows) IS_OS_OK=$($DSMADMC "SELECT count(node_name) FROM NODES WHERE (LOWER(PLATFORM_NAME) LIKE LOWER ('%${PLATFORM[$DEPL_PACK_ID]}%') OR LOWER(CLIENT_OS_NAME) LIKE LOWER ('%${PLATFORM[$DEPL_PACK_ID]}%')) AND (LOWER(CLIENT_SYSTEM_ARCHITECTURE) LIKE LOWER('%${ARCHITECTURE[$DEPL_PACK_ID]}%') OR TRIM(CLIENT_SYSTEM_ARCHITECTURE) = '' OR CLIENT_SYSTEM_ARCHITECTURE IS NULL) AND (LOWER(PLATFORM_NAME) NOT LIKE '%deploymgr%') and node_name=upper('$NODE')") ;; Linux) IS_OS_OK=$($DSMADMC "SELECT count(node_name) FROM NODES WHERE (LOWER(PLATFORM_NAME) LIKE LOWER ('%${PLATFORM[$DEPL_PACK_ID]}%') OR LOWER(CLIENT_OS_NAME) LIKE LOWER ('%${PLATFORM[$DEPL_PACK_ID]}%')) AND (LOWER(CLIENT_SYSTEM_ARCHITECTURE) LIKE LOWER('%x86%') OR LOWER(CLIENT_SYSTEM_ARCHITECTURE) LIKE LOWER('%x64%') OR TRIM(CLIENT_SYSTEM_ARCHITECTURE) = '' OR CLIENT_SYSTEM_ARCHITECTURE IS NULL) AND (LOWER(PLATFORM_NAME) NOT LIKE '%deploymgr%') and node_name=upper('$NODE')") ;; AIX) IS_OS_OK=$($DSMADMC "SELECT count(node_name) FROM NODES WHERE (LOWER(PLATFORM_NAME) LIKE LOWER ('%${PLATFORM[$DEPL_PACK_ID]}%') OR LOWER(CLIENT_OS_NAME) LIKE LOWER ('%${PLATFORM[$DEPL_PACK_ID]}%')) AND (LOWER(CLIENT_SYSTEM_ARCHITECTURE) LIKE LOWER('%ppc%') OR TRIM(CLIENT_SYSTEM_ARCHITECTURE) = '' OR CLIENT_SYSTEM_ARCHITECTURE IS NULL) AND (LOWER(PLATFORM_NAME) NOT LIKE '%deploymgr%') and node_name=upper('$NODE')") ;; *) printf "${red}Valami a szkript altal nem ismert platform-ot (${PLATFORM[$DEPL_PACK_ID]}) akarsz teriteni.${end}\n\n" | tee -a $LOG_FILE continue; ;; esac if [[ $IS_OS_OK -ne 1 ]]; then printf "${red}A node OS-e es/vagy architekturaja nem egyezik a telepiteni kivanteval!${end}\n\n" | tee -a $LOG_FILE continue; fi VERSIONNUM=$(echo ${VERSION[$DEPL_PACK_ID]}| sed 's/\.//g') # UTEMEZESEK BEDEFINIALASA RC=0 case "${PLATFORM[$DEPL_PACK_ID]}" in Windows) $DSMADMC "DEFINE SCHEDULE ${DEPL_DOM_NAME} ${DEPL_SCH_NAME} ACTION=DEPLOY OBJECTS='${FILESPACE[$DEPL_PACK_ID]}${HL_NAME[$DEPL_PACK_ID]}\* ..\IBM_ANR_WIN\\' DURATION=1 DURUNITS=HOURS PERUNITS=ONETIME STARTDATE=${STARTDATE} STARTTIME=${STARTTIME} OPTIONS=\"-FROMNODE=${PACK_NODE[$DEPL_PACK_ID]} -POSTSCHEDULECMD='..\IBM_ANR_WIN\V${VERSIONNUM}\\${LL_NAME[$DEPL_PACK_ID]} SCHEDULE=${DEPL_SCH_NAME} DOMAIN=${DEPL_DOM_NAME} AUTODEPLOY=NOREBOOT nodeinfo=TBD' -SUB=YES -REPLACE=ALL\"" | tee $TMP_FILE >> $LOG_FILE; ;; Linux) $DSMADMC "DEFINE SCHEDULE ${DEPL_DOM_NAME} ${DEPL_SCH_NAME} ACTION=DEPLOY OBJECTS='${HL_NAME[$DEPL_PACK_ID]}* /opt/tivoli/tsm/client/IBM_ANR_UNX/' DURATION=1 DURUNITS=HOURS PERUNITS=ONETIME STARTDATE=${STARTDATE} STARTTIME=${STARTTIME} OPTIONS=\"-FROMNODE=${PACK_NODE[$DEPL_PACK_ID]} -POSTSCHEDULECMD='/opt/tivoli/tsm/client/IBM_ANR_UNX/v${VERSIONNUM}/${LL_NAME[$DEPL_PACK_ID]}>/opt/tivoli/tsm/client/IBM_ANR_UNX/v${VERSIONNUM}/upmin#SCHEDULE=${DEPL_SCH_NAME}#DOMAIN=${DEPL_DOM_NAME}#nodeinfo2=TBD' -SUB=YES -REPLACE=ALL\"" | tee $TMP_FILE >> $LOG_FILE; ;; AIX) $DSMADMC "DEFINE SCHEDULE ${DEPL_DOM_NAME} ${DEPL_SCH_NAME} ACTION=DEPLOY OBJECTS='${HL_NAME[$DEPL_PACK_ID]}* /usr/tivoli/tsm/client/IBM_ANR_UNX/' DURATION=1 DURUNITS=HOURS PERUNITS=ONETIME STARTDATE=${STARTDATE} STARTTIME=${STARTTIME} OPTIONS=\"-FROMNODE=${PACK_NODE[$DEPL_PACK_ID]} -POSTSCHEDULECMD='/usr/tivoli/tsm/client/IBM_ANR_UNX/v${VERSIONNUM}/${LL_NAME[$DEPL_PACK_ID]}>/usr/tivoli/tsm/client/IBM_ANR_UNX/v${VERSIONNUM}/upmin#SCHEDULE=${DEPL_SCH_NAME}#DOMAIN=${DEPL_DOM_NAME}#nodeinfo2=TBD' -SUB=YES -REPLACE=ALL\"" | tee $TMP_FILE >> $LOG_FILE; ;; *) printf "${red}Valami a szkript altal nem ismert platform-ot (${PLATFORM[$DEPL_PACK_ID]}) akarsz teriteni.${end}\n\n" continue; ;; esac if [[ $(grep -c "ANR2500I" $TMP_FILE) -ne 1 ]]; then printf "${red}A(z) ${DEPL_SCH_NAME} utemezes bedefinialasa sikertelen!${end}\n\n" if [[ $(grep -c "ANR2618E" $TMP_FILE) -gt 0 ]]; then printf "A ${DEPL_DOM_NAME} domainben mar letezik ilyen utemezes, lasd alabb. Hozzarendeljem ezt a node-ot (is) ehhez?\n${gry}" $DSMADMC "QUERY SCHEDULE ${DEPL_DOM_NAME} ${DEPL_SCH_NAME}" fi printf "${end}[i/n]:" read VALASZ if [[ $VALASZ =~ [^iI] ]]; then continue; fi fi # A NODE TARGETLEVEL-JENEK BEALLITASA $DSMADMC "UPDATE NODE $NODE TARGETLEVEL=${VERSION[$DEPL_PACK_ID]}" | tee -a $LOG_FILE if [[ ${PIPESTATUS[0]} -ne 0 ]]; then printf "${red}A(z) node TARGETLEVEL-enek beallitasa ${VERSION[$DEPL_PACK_ID]}-re sikertelen!${end}\n\n" | tee -a $LOG_FILE continue; fi # NODE ASSZOCIACIOK BEDEFINIALASA $DSMADMC "DEFINE ASSOCIATION ${DEPL_DOM_NAME} ${DEPL_SCH_NAME} ${NODE}" | tee -a $LOG_FILE if [[ ${PIPESTATUS[0]} -ne 0 ]]; then printf "${red}A(z) $NODE node hozzarendelese a(z) ${DEPL_SCH_NAME} utemezeshez sikertelen!${end}\n\n" | tee -a $LOG_FILE continue; fi echo done fi done