################################################################################ ## ## build_cube.sh ## ## The purpose of this script is refresh/rebuild an Essbase cube. ## ## $Date: 2010-06-16 13:18:47 -0500 (Wed, 16 Jun 2010) $ ## $Revision: 11921 $ ## $Author: mike $ ## $HeadURL: svn://143.91.78.249/apps/VFrame/essbase/trunk/Scripts/build_cube.sh $ ## ## ################################################################################ ## Modifications: ## Date Name Description ################################################################################ ## ## 01/31/2009 Mike Reid Initial file. ## Revision 1.1 ## ## 04/06/2009 M.Reid Modified to use encrypted user and password informa- ## Revision 1.2 tion stored in MaxL scripts. ## Eliminated duplicate info being written to cube.log, ## and added date-time-pid to cube.log messages. ## ## 04/24/2009 M.Reid Ported to DEV server vfrtpan09. ## ## 04/28/2009 M.Reid Set return code 5 when dataload errors occur. ## ## 05/25/2009 M.Reid Add MaxL statement timestamping. ## ## 05/27/2009 M.Reid Comment-out the noconnect step before swap. This ## change will alleviate problem OBIEE is having - where ## BI Server loses connection with Essbase after forced ## logout by the build_cube.sh process. ## ## 07/17/2009 M.Reid Added dataload error count to status table update. ## ## 12/23/2009 M.Reid Suppress rc=5 for dataload errors and ## Enable copy of dataload error files to temp error ## directory for notification alerts. ## ## 01/05/2010 M.Reid Converted to bash shell from korn shell to allow ## Autosys to run the script from another server. ## ## 02/20/2010 M.Reid Several new features add: ## - modified data load procedure to support loading data ## from files and without load rule with support for ## name substitution in filenames. ## - ignore errors specified in build_cube.properties, ## see exec_essmsh function. ## - new command line param -L, used to load data into ## existing backup cube without clearing it. ## ## 04/02/2010 M.Reid EIC version of cube refresh process. This version ## should work for all EIC apps. ## ## ## 04/05/2010 M.Reid EIC global options installed: ## 1. Oracle Wallet ## 2. Option for handling dataload error files ## 3. Gate Status Option ## 4. NoConnect Before Swap ## 5. get_sysvar replaces get_rptvar ## (need to convert curr_mo to curr_mo_no in ## the sysvar tables for CDS and Quantas.) ## ## 06/15/2010 M.Reid Correction: gate status was not being updated due to ## coding error. ## ## 02/20/2015 M. Akkal Added option for parallel data load ## ################################################################################ #------------------------------------------------------------------------------# # Mandatory usage flag # -b option builds and swaps only if completion time is within allowed range # -s option swaps the cube immediately # -A option build and swaps the cube immediately # -B option forces a build cube (NO Swap) # -L option compound data load, does not clear backup cube, no swap #------------------------------------------------------------------------------# USAGE[1]="nohup $0 & \n" USAGE[2]="-A build and Swap immediately\n" USAGE[3]="-B force build\n" USAGE[4]="-b Build, check time and swap\n" USAGE[5]="-L skip to dataload\n" USAGE[6]="-s swap only\n" #------------------------------------------------------------------------------- # Options - default values for build_cube.properties options #------------------------------------------------------------------------------- Oracle_Wallet="Y" # Using Oracle_Wallet [Y|N] Dataload_Error_Handling="1" # Options for handling dataload error files Gate_Status_Option="N" # Using Vframe gate status NoConnect_Before_Swap="Y" # Disable Essbase connections before swap [Y|N] # Vframe Essbase environment file . ~/.ess_env . $VF_BIN/build_cube.properties VSII_LOG=$VF_LOG"/"$2"_vsii.lst" VSII_ERR=$VF_LOG"/"$2"_vsii.err" export VSII_SUMM=$VF_LOG"/"$2"_vsii.log" rm -f $VSII_LOG rm -f $VSII_ERR rm -f $VSII_SUMM function show_usage2 { USAGE_NUM=1 while [[ -n ${USAGE[$USAGE_NUM]} ]]; do if (( $USAGE_NUM == 1 )); then printf "\nusage: ${USAGE[$USAGE_NUM]}" >& 2 else printf " ${USAGE[$USAGE_NUM]}" >& 2 fi USAGE_NUM=$(( $USAGE_NUM + 1 )) done exit 1 } if (( $# != 3 )) || ([[ -z "$2" ]] && [[ -z "$3" ]]) ; then show_usage2 fi # flow control variables #BLD_FLG="N" # Default, assume no build, replaced by DIM_BLD_FLG CLEAR_WKAPP_FLG="N" # Default, assume no clear work app (backup cube) DIM_BLD_FLG="N" # Default, assume no dimension build DATA_LOAD_FLG="N" # Default, assume no data load CALC_FLG="N" # Default, assume no calc or agg SWP_FLG="C" # Default, check if swap is needed PL_FLG="N" # Default, parallel load is not enabled Mopt=0 # flag for single or multiple options Viador_Refresh=N # Default, this variable is obsolete ASO_FLG=N # Default, this variable may be set in the application.var file ASO_TOTAL_SIZE=2 # Default for ASO, this variable may be set in the application.var file DATA_LOAD_ERR=0 # Default, indicator for setting return code when dataload errors VF_DBLOG_ERR_REC_CNT=0 # flag for recording errors from dataload err_cnt=0 # Default, data load errors work counter swapRetryCnt=0 # swap Retry Count incremental variable declaration SCRIPT_NM=$(basename $0 | cut -d'.' -f1) # program name from the shell name CUBE_NM=$2 VF_DBLOG_FILEID=$($VF_BIN/get_fileid.sh "$CUBE_NM") # Since fileid is not known, Cube Name is passed RC=$? # cannot invoke abortif function because we have not called script_header yet if (( $RC != 0 )); then #Vframe script utilities . $VF_BIN/script_header.sh abort "$CUBE_NM - Error $RC getting file id for $CUBE_NM from ODS.CPM_FEED table" fi VF_DBLOG_FLG=Y # to indicate requirement to log into db in vfr_feed_status #Vframe script utilities . $VF_BIN/script_header.sh ################################################################################ # Script Functions ################################################################################ function local_logscript { # this is to avoid typing the same info twice, # once for the shell log and again for the cube log log_script $1 $2 $3 LOG_ENTRY_ID="$(date +'%Y-%m-%d %H:%M:%S')_$$" # date time and pid echo $LOG_ENTRY_ID $3 >> $LOG_FLE } function create_scr_hdr { # create dimension build script cat << EOF > $SCR_FLE set timestamp on; login $ESS_USRs $ESS_PWDs on $ESS_SVR; spool on to $TMP_LOG_FLE; EOF abortif $? "Error trying to build header for $SCR_FLE" } function append_scr_trl { #complete the dimension build script cat << EOF >> $SCR_FLE logout; spool off; exit; EOF abortif $? "Error trying to complete $SCR_FLE" } function exec_essmsh { #essmsh -D $1 $ESS_PK 1>>$2 2>&1 essmsh -D $1 $ESS_PK 2>&1 |tee -a $2 |tee -a $VSII_LOG echo "essmsh -D $1 $ESS_PK" 2>&1 |tee -a $2 |tee -a $VSII_LOG RC=$? abortif $RC "Errors $3 in running script $SCR_FLE check $LOG_FLE" # grep temp log file for errors, ignore errors specified in build_cube.properties grep " ERROR - [0-9]" $TMP_LOG_FLE > $TMP_LOG_FLE.errs # if [ $test_flg -eq 0 ];then # echo "ERROR - 1013290" |tee -a $TMP_LOG_FLE.errs # test_flg=$((++test_flg)) # fi #if [ $swapRetryCnt -lt $swapRetryLimit ] && ([ "$3" == "Script Noconnect" ] || [ "$3" == "Killscript" ]); then # echo "ERROR - 1051008 - Invalid login id - logout failed" > $TMP_LOG_FLE.errs #fi toterrs=$(grep "ERROR - [0-9]" $TMP_LOG_FLE.errs | wc -l) for ie in ${Ignore_Error[*]} do ierr=$(grep "$ie" $TMP_LOG_FLE.errs | wc -l) toterrs=$(($toterrs - $ierr)) done if [ $toterrs -gt 0 ]; then echo "----------- ERROR -----------" |tee -a $VSII_ERR echo " " |tee -a $VSII_ERR echo "Errors found for $3 during grep of $TMP_LOG_FLE" |tee -a $VSII_ERR if [ "$(grep -i "ERROR" $TMP_LOG_FLE.errs )" ] && ([ "$3" == "Script Noconnect" ] || [ "$3" == "Killscript" ]); then #if [ "$(grep -i "ERROR - 1051008 - Invalid login id - logout failed" $TMP_LOG_FLE.errs )" ] || [ "$(grep -i "ERROR - 1013290" $TMP_LOG_FLE.errs )" ] || [ "$(grep -i "ERROR - 1013018 " $TMP_LOG_FLE.errs)" ];then echo "Found Swap Failure Error running force kill function in maxl" |tee -a $VSII_ERR cp $TMP_LOG_FLE.errs $VSII_ERR cat << EOF > $SCR_KIL set timestamp on; login $ESS_USRs $ESS_PWDs on $ESS_SVR; spool on to $TMP_LOG_FLE; alter system logout session on application $PRODAPP force; alter system kill request on application $PRODAPP; shell sleep 10; logout; spool off; exit; EOF abortif $? "$PRODAPP - Error in appending to $SCR_KIL for kill session using maxl" echo "Force Killing the PID in case of Swap Failure" ssh $ESS_INST_ID@$ESS_SVR kill -9 $(ps -ef | grep -w $PRODAPP | grep -w $ESS_INST_ID | awk '{print $2}') if [ $swapRetryCnt -lt $swapRetryLimit ]; then export retry_swap="Y" #echo " Retrycount" $swapRetryCnt swapRetryCnt=$((swapRetryCnt+1)) exec_essmsh $SCR_KIL $LOG_FLE "Killscript" fi fi if [ -e $TMP_LOG_FLE.errs ];then cp $TMP_LOG_FLE.errs $VSII_ERR abort "Errors found for $3 during grep of $TMP_LOG_FLE" fi fi if [ -e $TMP_LOG_FLE ];then rm $TMP_LOG_FLE rm $TMP_LOG_FLE.errs fi } function update_gate_status { ############################################################################### # Call shell upd_gate_status.sh to update status_feed table ############################################################################### log_script INFO 0 "$PRODAPP - Starting to update gate status" #echo "$PRODAPP - Starting to update gate status" >> $LOG_FLE echo "$PRODAPP - Starting to update gate status" 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG Cube_Name="cube - "$PRODAPP Curr_Msg=$(date '+%m/%d %H:%M OK;') set -x $VF_BIN/upd_gate_status.sh -n "$Cube_Name" -a "$Curr_Msg" RC=$? set +x if (( $RC != 0 )); then printf "upd_gate_status.sh ERROR ERROR" >& 2 log_master ABORT $RC "Error in updating gate status, please check $VF_LOG/upd_gate_status.log for more details" fi } while getopts ":s:b:B:A:L:" opt; do case $opt in s ) CLEAR_WKAPP_FLG="N" DIM_BLD_FLG="N" DATA_LOAD_FLG="N" CALC_FLG="N" SWP_FLG="Y" CDIR=$2 CFLE=$3 let Mopt=Mopt+1; ;; A ) CLEAR_WKAPP_FLG="Y" DIM_BLD_FLG="Y" DATA_LOAD_FLG="Y" CALC_FLG="Y" SWP_FLG="Y" CDIR=$2 CFLE=$3 let Mopt=Mopt+1; ;; b ) CLEAR_WKAPP_FLG="Y" DIM_BLD_FLG="Y" DATA_LOAD_FLG="Y" CALC_FLG="Y" SWP_FLG="C" CDIR=$2 CFLE=$3 let Mopt=Mopt+1; ;; B ) CLEAR_WKAPP_FLG="Y" DIM_BLD_FLG="Y" DATA_LOAD_FLG="Y" CALC_FLG="Y" SWP_FLG="N" Gate_Status_Option="N" CDIR=$2 CFLE=$3 let Mopt=Mopt+1; ;; L ) CLEAR_WKAPP_FLG="N" DIM_BLD_FLG="N" DATA_LOAD_FLG="Y" CALC_FLG="Y" SWP_FLG="N" Gate_Status_Option="N" CDIR=$2 CFLE=$3 let Mopt=Mopt+1; ;; * ) show_usage2 ;; esac done shift $(($OPTIND - 1)) if [ $Mopt -ne 1 ] then show_usage2 fi ################################################################################ #Step 0: Establish cube specific variables from the application var file ################################################################################ #------------------------------------------------------------------------------# #Step 0: Source variables from the cube .var file #------------------------------------------------------------------------------# . $ESS_PATH/$CDIR/$CFLE abortif $? "Error sourcing file $ESS_PATH/$CDIR/$CFLE" #------------------------------------------------------------------------------# #Step 0: Set variables for script dir, file, log #------------------------------------------------------------------------------# SCR_DIR=$ESS_PATH/$PRODAPP #PRODAPP is from the application var file SCR_FLE=$SCR_DIR/$PRODAPP.mxls SCR_KIL=$SCR_DIR/${PRODAPP}_KIL.mxls #mxls file for killing the session. LOG_FLE=$VF_LOG/$PRODAPP.log TMP_LOG_FLE=$VF_LOG/$PRODAPP.log.tmp #VSII_LOG=$(echo $LOG_FLE | awk -F. '{print $1"_vsii.lst"}') #VSII_ERR=$(echo $LOG_FLE | awk -F. '{print $1"_vsii.err"}') #export VSII_SUMM=$(echo $LOG_FLE | awk -F. '{print $1"_vsii.log"}') local_logscript INFO 0 "$PRODAPP - Removing any previous error file from - $ESS_PATH/$PRODAPP/error/*.*" rm -f $ESS_PATH/$PRODAPP/error/*.* 2>/dev/null #------------------------------------------------------------------------------# #Setp 0: Get Sys_Var values and write to log #------------------------------------------------------------------------------# ###CURR_YR=$($VF_BIN/get_sysvar.sh "curr_yr") ###CURR_MO_NO=$($VF_BIN/get_sysvar.sh "curr_mo") CURR_YR=$($VF_BIN/get_sysvar.sh "curr_yr") CURR_MO=$($VF_BIN/get_sysvar.sh "curr_mo_no") #log_script INFO 0 "$PRODAPP - $CURR_YR $CURR_MO" >> $LOG_FLE log_script INFO 0 "$PRODAPP - $CURR_YR $CURR_MO" 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG #------------------------------------------------------------------------------# #Step A: If needed, begin the BUILD CUBE Block. for -B, -b, -A options #------------------------------------------------------------------------------# if [ $CLEAR_WKAPP_FLG = "Y" ] then ### #----------------------------------------------------------------------# ### #Step 1: Unload app -- THIS STEP IS NOT NECESSARY!! ### #----------------------------------------------------------------------# ### local_logscript INFO 0 "$PRODAPP - Starting Script1" ### ksh $VF_BIN/unld_ess_app.sh -l "$WORKAPP" ### abortif $? "$PRODAPP - Errors executing unld_ess_app in Script1" ### #----------------------------------------------------------------------# #Step 2: Create and run script to clear out working copy of db #----------------------------------------------------------------------# local_logscript INFO 0 "$PRODAPP - Starting Script2" create_scr_hdr cat << EOF >> $SCR_FLE alter database $WORKAPP.$WORKDB reset; shell sleep 10; alter application $WORKAPP unload database $WORKDB; EOF abortif $? "$PRODAPP - Error in appending to $SCR_FLE for Script2" append_scr_trl exec_essmsh $SCR_FLE $LOG_FLE Script2 #----------------------------------------------------------------------# #Step 2a: Copy template outline and set permissions #----------------------------------------------------------------------# local_logscript INFO 0 "$PRODAPP - starting to copy template and set permissions" #chmod 664 $ESS_APP/$WORKAPP/$WORKDB/$WORKDB.otl >> $LOG_FLE chmod 664 $ESS_APP/$WORKAPP/$WORKDB/$WORKDB.otl 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG abortif $? "$PRODAPP - Error in CHMOD" #cp -p $SCR_DIR/$TEMPOTL $ESS_APP/$WORKAPP/$WORKDB/$WORKDB.otl >> $LOG_FLE cp -p $SCR_DIR/$TEMPOTL $ESS_APP/$WORKAPP/$WORKDB/$WORKDB.otl 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG abortif $? "$PRODAPP - Error in COPY" fi if [ $DIM_BLD_FLG = "Y" ] then #------------------------------------------------------------------------# #Step 3: Loop thru all the dimension build rule files, remove existing err files, add for each dim and run script #------------------------------------------------------------------------# local_logscript INFO 0 "$PRODAPP - Starting Script3 (build rule)" create_scr_hdr for rfile in ${build_rule[*]} do #----------------------------------------------------------------# #Step 3a: Delete any rejected error files prior to the new build #----------------------------------------------------------------# mkdir -p $SCR_DIR/error if [ -f $SCR_DIR/error/$rfile.err ] then local_logscript INFO 0 "$PRODAPP - Removing previous error file - $SCR_DIR/error/$rfile.err" rm $SCR_DIR/error/$rfile.err fi #----------------------------------------------------------------# #Step 3b: append to dimension build script #----------------------------------------------------------------# cat << EOF >> $SCR_FLE import database $WORKAPP.$WORKDB dimensions connect as $ESS_DW_USRs identified by $ESS_DW_PWDs using server rules_file $rfile on error append to '$SCR_DIR/error/$rfile.err'; EOF abortif $? "$PRODAPP - Error in appending for $rfile to $SCR_FLE for Script3" done append_scr_trl exec_essmsh $SCR_FLE $LOG_FLE "dimension builds Script3" #------------------------------------------------------------------------# #Step 3c: Check for rejected records in dimension build rules #------------------------------------------------------------------------# for rfile in ${build_rule[*]} do if [ -f $SCR_DIR/error/$rfile.err ] then local_logscript WARN 0 "$PRODAPP - Warning - Dimension build $rfile has produced errors" fi done fi if [ $DATA_LOAD_FLG = "Y" ] then if [ $PL_FLG = "Y" ] then #------------------------------------------------------------------------# #Step 4: Loop thru all load rule files #------------------------------------------------------------------------# local_logscript INFO 0 "$PRODAPP - Starting Script4 (load rule)" create_scr_hdr if [ -f $ESS_PATH/$PRODAPP/error/${PRODAPP}_Load.err ] then local_logscript INFO 0 "$PRODAPP - Removing previous error file - $ESS_PATH/$PRODAPP/error/${PRODAPP}_Load.err" rm $ESS_PATH/$PRODAPP/error/${PRODAPP}_Load.err fi LR_List='' LR_ind=0 for rfile in ${load_rule[*]} do #----------------------------------------------------------------# #Step 4a: Delete any rejected error files prior to the new load #----------------------------------------------------------------# if [ $LR_ind -ne 0 ] then LR_List+=','$(echo $rfile| gawk '{split($1,arr,","); print arr[1]}') else LR_List+=$(echo $rfile| gawk '{split($1,arr,","); print arr[1]}') fi let LR_ind=LR_ind+1; done #----------------------------------------------------------------# #Step 4b: Load data in a parallel mode #----------------------------------------------------------------# cat << EOF >> $SCR_FLE import database $WORKAPP.$WORKDB data connect as $ESS_DW_USRs identified by $ESS_DW_PWDs using multiple rules_file $LR_List to load_buffer_block starting with buffer_id 100 on error write to '$SCR_DIR/error/${PRODAPP}_Load.err'; EOF echo "SCR_FILE is " $SCR_FLE abortif $? "$PRODAPP - Error in appending for $rfile to $SCR_FLE for Script4" append_scr_trl exec_essmsh $SCR_FLE $LOG_FLE "data loads Script4" else #------------------------------------------------------------------------# #Step 4: Loop thru all load rule files #------------------------------------------------------------------------# local_logscript INFO 0 "$PRODAPP - Starting Script4 (load rule)" create_scr_hdr for rfile in ${load_rule[*]} do #----------------------------------------------------------------# #Step 4a: Delete any rejected error files prior to the new load #----------------------------------------------------------------# var1=$(echo $rfile| gawk '{split($1,arr,","); print arr[1]}') var2=$(echo $rfile| gawk '{split($1,arr,","); print arr[2]}') var3=$(echo $rfile| gawk '{split($1,arr,","); print arr[3]}') # This functionality is to support the original build_cube script if ([[ -z $var3 ]]); then var3=$var1 fi if [ -f $ESS_PATH/$PRODAPP/error/$var3.err ] then local_logscript INFO 0 "$PRODAPP - Removing previous error file - $ESS_PATH/$PRODAPP/error/$var3.err" rm $ESS_PATH/$PRODAPP/error/$var3.err fi #----------------------------------------------------------------# #Step 4b: Loop thru and build script to run all data load rules #----------------------------------------------------------------# if ([[ -z $var3 ]]); then var3=$var1 fi echo "LOADFILE_DIR - $LOADFILE_DIR" cd $LOADFILE_DIR lfilelist=$(ls $var2) ###echo "var2 = $var2" >> $LOG_FLE ###echo "lfilelist = $lfilelist" >> $LOG_FLE if [[ $var2 = "" ]] # sql build then cat << EOF >> $SCR_FLE import database $WORKAPP.$WORKDB data connect as $ESS_DW_USRs identified by $ESS_DW_PWDs using server rules_file $var1 on error append to '$SCR_DIR/error/$var3.err'; EOF abortif $? "$PRODAPP - Error in appending for $rfile to $SCR_FLE for Script4" elif [[ $var1 = "" ]] # file build with no rule then for v2file in $lfilelist do cat << EOF >> $SCR_FLE import database $WORKAPP.$WORKDB data from data_file '$LOADFILE_DIR/$v2file' on error append to '$SCR_DIR/error/$var3.err'; EOF abortif $? "$PRODAPP - Error in appending for $v2file to $SCR_FLE for Script4" done else # file build with rule for v2file in $lfilelist do cat << EOF >> $SCR_FLE import database $WORKAPP.$WORKDB data from data_file '$LOADFILE_DIR/$v2file' using server rules_file $var1 on error append to '$SCR_DIR/error/$var3.err'; EOF abortif $? "$PRODAPP - Error in appending for $v2file to $SCR_FLE for Script4" done fi done append_scr_trl exec_essmsh $SCR_FLE $LOG_FLE "data loads Script4" #------------------------------------------------------------------------# #Step 4c:Check for rejected records and save a copy of error files #------------------------------------------------------------------------# for rfile in ${load_rule[*]} do var1=$(echo $rfile| gawk '{split($1,arr,","); print arr[1]}') var2=$(echo $rfile| gawk '{split($1,arr,","); print arr[2]}') var3=$(echo $rfile| gawk '{split($1,arr,","); print arr[3]}') # Default err file to rule name if not explicitly given if ([[ -z $var3 ]]); then var3=$var1 fi if [ -f $SCR_DIR/error/$var3.err ] then DATA_LOAD_ERR=$DATALOAD_ERR_RC # compute error count for status update, 3 lines per error wc_val=$(wc -l $SCR_DIR/error/$var3.err) err_cnt=$((${wc_val%%/*} / 3)) VF_DBLOG_ERR_REC_CNT=$((VF_DBLOG_ERR_REC_CNT + err_cnt)) if [ $Dataload_Error_Handling = "1" ]; then #Copy the error files if any in the new build cp $SCR_DIR/error/$var3.err $ESS_TEMPERRS/$PRODAPP.$LOG_JOB_ID.$var3.err abortif $? "Error copying dataload error files to $ESS_TEMPERRS" fi local_logscript WARN 0 "$PRODAPP - Warning - Data load $var3 has produced $err_cnt rejected records" fi done fi fi #------------------------------------------------------------------------# #A new option added for parallel load #------------------------------------------------------------------------# if [ $CALC_FLG = "Y" ] then if [ $ASO_FLG = "Y" ] then #----------------------------------------------------------------# #Step 5a: Aggr for ASO cubes, based on ASO_FLG in .var file #----------------------------------------------------------------# local_logscript INFO 0 "$PRODAPP - Starting Script5 (Calc) for ASO" create_scr_hdr cat << EOF >> $SCR_FLE execute aggregate process on database $WORKAPP.$WORKDB stopping when total_size exceeds $ASO_TOTAL_SIZE; shell sleep 10; alter application $WORKAPP disable connects; shell sleep 10; alter application $WORKAPP unload database $WORKDB; EOF abortif $? "$PRODAPP - Error in appending ASO Aggr to $SCR_FLE for Script5" append_scr_trl exec_essmsh $SCR_FLE $LOG_FLE "calc scripts Script5 (Calc)" else #----------------------------------------------------------------# #Step 5b: Calc for BSO cubes #----------------------------------------------------------------# local_logscript INFO 0 "$PRODAPP - Starting Script5 (Calc)" calc_flg=Y create_scr_hdr for crul in ${calc_rule[*]} do calc_flg=N cat << EOF >> $SCR_FLE execute calculation $WORKAPP.$WORKDB.$crul; EOF abortif $? "$PRODAPP - Error in appending for $crul to $SCR_FLE for Script5" done if [[ $calc_flg == Y ]] then cat << EOF >> $SCR_FLE execute calculation default on $WORKAPP.$WORKDB; EOF abortif $? "$PRODAPP - Error in appending calc_default to $SCR_FLE for Script5" fi cat << EOF >> $SCR_FLE alter application $WORKAPP disable connects; shell sleep 10; alter application $WORKAPP unload database $WORKDB; EOF abortif $? "$PRODAPP - Error in appending app state to $SCR_FLE for Script5" append_scr_trl exec_essmsh $SCR_FLE $LOG_FLE "calc scripts Script5 (Calc)" fi #------------------------------------------------------------------------# #CUBE Building ends here #------------------------------------------------------------------------# local_logscript INFO 0 "$PRODAPP - Cube build successful" #------------------------------------------------------------------------# # Call shell upd_cube_note.sh to update Note text in Essbase #------------------------------------------------------------------------# log_script INFO 0 "$PRODAPP - Updating Essbase note text" #echo "$PRODAPP - Updating Essbase note text" >> $LOG_FLE echo "$PRODAPP - Updating Essbase note text" 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG Note_Txt="Refreshed $(date '+%m/%d %H:%M')" $VF_BIN/upd_cube_note.sh -c "$WORKAPP" "$Note_Txt" "$WORKDB" RC=$? if (( $RC != 0 )); then printf "upd_cube_note.sh ERROR ERROR" >& 2 log_master ABORT $RC "Error updating note text, check $VF_LOG/upd_cube_note.log" fi fi #------------------------------------------------------------------------------# #Step 5a: if FLT_FLG is set to Y in var file, then apply filters by calling Security_Rbld_Cube.sh #------------------------------------------------------------------------------# if [ $FLT_FLG = "Y" ] then local_logscript INFO 0 "$PRODAPP - Starting Script5a apply filters for ASO" $VF_BIN/Security_Rbld_Cube.sh $CDIR $CFLE RC=$? if (( $RC != 0 )); then printf "upd_cube_note.sh ERROR ERROR" >& 2 log_master ABORT $RC "Error updating note text, check $VF_LOG/upd_cube_note.log" fi #------------------------------------------------------------------------# # Apply filters ends here #------------------------------------------------------------------------# local_logscript INFO 0 "$PRODAPP - Apply filters successful" #------------------------------------------------------------------------# # Call shell upd_cube_note.sh to update Note text in Essbase #------------------------------------------------------------------------# log_script INFO 0 "$PRODAPP - Apply filters successful" echo "$PRODAPP - Apply filters successful" 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG Note_Txt="Refreshed $(date '+%m/%d %H:%M')" fi #------------------------------------------------------------------------------# #Step B: if -b option, check if swap is allowed by checking sys_var table #------------------------------------------------------------------------------# if [ $SWP_FLG = "C" ] then #Now Check to see if the time is right to Swap from sys_var table SQL_FLE=$VF_SQL/build_cube.sql if [ ! -f $SQL_FLE ] then abort "$PRODAPP - Error in reading $SQL_FLE to check swap time" fi #Check the time limits in sys_var table Akey=0 #initialize to 0 if [ $Oracle_Wallet = "Y" ]; then Akey=$(sqlplus -s /@$ORACLE_SID @$SQL_FLE) else Akey=$(sqlplus -s $DB_USER/$DB_PWD @$SQL_FLE) fi abortif $? "Error getting Akey by running $SQL_FLE" if [ $Akey -eq 2 ] then local_logscript ABORT 0 "$PRODAPP - SWAP Time out of bounds - Exiting script" $Gate_Status_Option="N" # do not update gate status . $VF_BIN/script_trailer.sh # Exiting the program normally elif [ $Akey -eq 0 ] then SWP_FLG="Y" local_logscript INFO 0 "$PRODAPP - SWAP Time not out of bounds - continuing" else abort "$PRODAPP - Error from DB, No Swap.. Exiting script" fi fi #------------------------------------------------------------------------------# #Step C: if necessary do a swap. for -A, -s, and -b options. # -b checks if the sys_var to decide to swap #------------------------------------------------------------------------------# # THIS STEP NEEDS TO BE CHANGED FOR ASO CUBES DEFAULT DIRECTORIES #------------------------------------------------------------------------------# set -x #if [ $CORP_USER_ACCESS = "Y" ] #then echo " " echo "----------------------------------------------------------- " 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG echo "Starting to apply user access on $WORKAPP.$WORKDB " 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG echo "----------------------------------------------------------- " 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG echo " " sh $VF_BIN/apply_swap_user_access.sh $WORKAPP $WORKDB $TMP_LOG_FLE $PRODAPP 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG echo " " echo "----------------------------------------------------------- " 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG echo "Completed applying user access on $WORKAPP.$WORKDB " 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG echo "----------------------------------------------------------- " 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG echo " " #fi set +x set -x if [ $CORP_USER_ACCESS = "Y" ] then echo " " echo "----------------------------------------------------------- " 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG echo "Starting to apply corporate user access on $WORKAPP.$WORKDB " 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG echo "----------------------------------------------------------- " 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG echo " " $VF_BIN/apply_corp_user_access.sh $WORKAPP $WORKDB $TMP_LOG_FLE 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG echo " " echo "----------------------------------------------------------- " 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG echo "Completed applying corporate user access on $WORKAPP.$WORKDB " 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG echo "----------------------------------------------------------- " 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG echo " " fi set +x set -x if [ $CORP_USER_ACCESS_BMC = "Y" ] then echo " " echo "----------------------------------------------------------- " 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG echo "Starting to apply corporate user access on $WORKAPP.$WORKDB " 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG echo "----------------------------------------------------------- " 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG echo " " $VF_BIN/apply_corp_user_access_BMC.sh $WORKAPP $WORKDB $TMP_LOG_FLE 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG echo " " echo "----------------------------------------------------------- " 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG echo "Completed applying corporate user access on $WORKAPP.$WORKDB " 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG echo "----------------------------------------------------------- " 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG echo " " fi set +x if [ $SWP_FLG = "Y" ] then set -f #Remove if the essdata1/app/App/Db directory is empty #local_logscript INFO 0 "$PRODAPP - Is $ESS_DATA/$PRODAPP/$PRODDB empty" #echo "$PRODAPP - Is $ESS_DATA/$PRODAPP/$PRODDB empty" >> $LOG_FLE echo "$PRODAPP - Is $ESS_DATA/$PRODAPP/$PRODDB empty" 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG if ([[ -n "$PRODAPP" ]] && [[ -n "$PRODDB" ]]) ; then if test -d $ESS_DATA/$PRODAPP/$PRODDB then File_Cnt=$(ls $ESS_DATA/$PRODAPP/$PRODDB | wc -w) if (( $File_Cnt == 0)); then local_logscript INFO 0 "$PRODAPP - $ESS_DATA/$PRODAPP/$PRODDB is empty" rmdir $ESS_DATA/$PRODAPP/$PRODDB local_logscript INFO 0 "$PRODAPP - Removed $PRODDB DB folder" rmdir $ESS_DATA/$PRODAPP local_logscript INFO 0 "$PRODAPP - Removed $PRODAPP App folder" else #local_logscript INFO 0 "$PRODAPP - $ESS_DATA/$PRODAPP/$PRODDB is not empty" #echo "$PRODAPP - $ESS_DATA/$PRODAPP/$PRODDB is not empty" >> $LOG_FLE echo "$PRODAPP - $ESS_DATA/$PRODAPP/$PRODDB is not empty" 2>&1 |tee -a $LOG_FLE |tee -a $VSII_LOG fi else local_logscript INFO 0 "$PRODAPP - $ESS_DATA/$PRODAPP/$PRODDB doesn't exist" #echo "$PRODAPP - $ESS_DATA/$PRODAPP/$PRODDB doesn't exist" >> $LOG_FLE fi else local_logscript INFO 0 "$PRODAPP - Either $PRODAPP (Prod App) or $PRODDB (Prod DB) is null" #echo "$PRODAPP - Either $PRODAPP (Prod App) or $PRODDB (Prod DB) is null" >> $LOG_FLE fi #------------------------------------------------------------------------# #Step noconnect: Script noconnect for setting appstate of prod app #------------------------------------------------------------------------# if [ $NoConnect_Before_Swap = "Y" ]; then local_logscript INFO 0 "$PRODAPP - Starting Script noconnect" # echo "ERROR - 1051008 - Invalid login id - logout failed" echo $TMP_LOG_FLE.errs # echo "ERROR - 1051008 - Invalid login id - logout failed" >> $TMP_LOG_FLE.errs create_scr_hdr echo $TMP_LOG_FLE.errs cat << EOF >> $SCR_FLE alter application $PRODAPP disable connects; shell sleep 6; alter system logout session on application "$PRODAPP" force; shell sleep 6; EOF abortif $? "$PRODAPP - Error in appending to $SCR_FLE for Script noconnect" append_scr_trl export retry_swap='N' # test_flg=0 exec_essmsh $SCR_FLE $LOG_FLE "Script Noconnect" if [ "$retry_swap" = "Y" ] ; then local_logscript INFO 0 "$PRODAPP - Re-Starting Script noconnect after swap failure" exec_essmsh $SCR_FLE $LOG_FLE "Script Re-Noconnect" fi #added for swap failure testing.retry is already called above. fi #------------------------------------------------------------------------# #Step 6: build and run the swap script (script 6) #------------------------------------------------------------------------# local_logscript INFO 0 "$PRODAPP - Starting Script6 (Swap db)" create_scr_hdr cat << EOF >> $SCR_FLE alter database $WORKAPP.$WORKDB unlock all objects; alter database $PRODAPP.$PRODDB unlock all objects; alter application $WORKAPP rename to $SWAPAPP; shell sleep 6; alter database $SWAPAPP.$WORKDB rename to $PRODDB; shell sleep 6; alter application $PRODAPP rename to $WORKAPP; shell sleep 6; alter database $WORKAPP.$PRODDB rename to $WORKDB; shell sleep 6; alter application $SWAPAPP rename to $PRODAPP; shell sleep 6; alter database $WORKAPP.$WORKDB reset; shell sleep 6; alter application $WORKAPP unload database $WORKDB; shell sleep 6; alter application $PRODAPP unload database $PRODDB; shell sleep 6; alter application $WORKAPP disable connects; shell sleep 6; alter application $PRODAPP enable connects; shell sleep 6; EOF abortif $? "$PRODAPP - Error in appending to $SCR_FLE for Script 6" append_scr_trl exec_essmsh $SCR_FLE $LOG_FLE "Swap Script 6" #Delete script file rm $SCR_FLE if [ -e $SCR_KIL ];then rm $SCR_KIL fi #------------------------------------------------------------------------# #Step 7: call unld_ess_app.sh to stop (not kill) ESSSVR # processes for $WORKAPP and $PRODAPP #------------------------------------------------------------------------# ksh $VF_BIN/unld_ess_app.sh -l "$WORKAPP $PRODAPP" RC=$? if (( $RC != 0 )) then log_script INFO 0 "$PRODAPP - $PRODAPP, $WORKAPP cleanup Successful after SWAP" #echo "$PRODAPP - $PRODAPP, $WORKAPP cleanup Successful after SWAP" >> $LOG_FLE else log_script INFO 0 "$PRODAPP - $PRODAPP, $WORKAPP unload and cleanup Successful after SWAP" #echo "$PRODAPP - $PRODAPP, $WORKAPP unload and cleanup Successful after SWAP" >> $LOG_FLE fi #------------------------------------------------------------------------# #Step 8: Rename nohup.out file - this keeps nohup.out from constantly # growing while saving the previous run's output #------------------------------------------------------------------------# if [ -f nohup.out ] then mv nohup.out nohup.old fi fi abortif $DATA_LOAD_ERR "$PRODAPP - Data Load Errors Found" if [ $CWA_FLG = "Y" ];then create_scr_hdr cat << EOF >> $SCR_FLE /* Extract for CPMCWA cube*/ export database $PRODAPP.$PRODDB using server report_file 'CPMCWA1' to data_file '$LOADFILE_DIR/COSP_SGA.txt'; export database $PRODAPP.$PRODDB using server report_file 'CPMCWA2' to data_file '$LOADFILE_DIR/IS_ACC.txt'; EOF append_scr_trl exec_essmsh $SCR_FLE $LOG_FLE "Aggregate View scripts Script (AGG)" fi #------------------------------------------------------------------------------# # Optional - Update Gate Status #------------------------------------------------------------------------------# if [ $Gate_Status_Option = "Y" ] then update_gate_status fi #Vframe script utilities . $VF_BIN/script_trailer.sh