#!/usr/bin/ksh
#####################################################
#The purpose of this script is to tell how long does
#it take for a specific cube to run,cube status,
#Estimate time hit calc and Estimate complete time.
#####################################################
. ~/.env
USAGE[1]="list_cube.sh R"
. $VF_BIN/script_header.sh
RunTime ( ) {
#For RunTime
#$1 = $SDate ; $3 = $SHr ; $4 = $SMin
#$2 = $CDate ; $5 = $CHr ; $6 = $CMin
#For Calc
#$1 = $SDate ; $3 = $SHr ; $4 = $SMin
#$2 = $CaclcDate ; $5 = $CalcHr ; $6 = $CalcMin
if [ $1 -eq $2 ]
then
StartTime=`expr \( $3 \* 60 \) + $4`
CompleteTime=`expr \( $5 \* 60 \) + $6`
expr $CompleteTime - $StartTime
else
StartTime=`expr \( \( 23 - $3 \) + $5 \) \* 60`
CompleteTime=`expr \( 60 - $4 \) + $6`
expr $StartTime + $CompleteTime
fi
}
LessThan10 ( ) {
#Hour compare
if [ $1 -lt 10 ]
then
echo "0$1"
else
echo "$1"
fi
}
Process ( ) {
CubeName="$1"
CubeNameLength=${#CubeName}
typeset -l Cube="$1.var"
FileName="build_cube.log"
CompleteFileName="$VF_LOG/$FileName"
Script5="Script5"
Script1="Script1"
Empty=""
typeset -i Total=0
typeset -i CalcTotal=0
typeset -i Avg=0
typeset -i CurHour=0
typeset -i NotOptionSwap=0
typeset -i NumOfRun=3
typeset -i FoundSwapOption=0
set -A Previous_idstring $(grep $Cube $CompleteFileName |tail -6|grep COMPLETED|nawk -F'|' '{print $2}'|sort -u)
Current_Id=`grep $Cube $CompleteFileName |tail -1|nawk -F'|' '{print $2}'`
CurrentHr=`grep $Cube $CompleteFileName |grep $Current_Id|grep START|cut -c 12,13`
CurrentMin=`grep $Cube $CompleteFileName |grep $Current_Id|grep START |cut -c 15,16`
CubeStatus=`grep $Current_Id $CompleteFileName|grep Script5|nawk -F'|' '{print $6}'|cut -f4 -d' '`
CubeStartTime="$CurrentHr:$CurrentMin"
#Check Calc status of current running cube
if [ -z $CubeStatus ]
then
HitCalc="No"
else
HitCalc="Yes"
HitCalcHr=`grep $Current_Id $CompleteFileName |grep Script5|cut -c 12,13`
HitCalcMin=`grep $Current_Id $CompleteFileName |grep Script5|cut -c 15,16`
HitCalcTime="$HitCalcHr:$HitCalcMin"
fi
for member in "${Previous_idstring[@]}"
do
SDate=`grep $Cube $CompleteFileName |grep $member|grep START|cut -c 9,10`
CDate=`grep $Cube $CompleteFileName |grep $member|grep COMPLETED|cut -c 9,10`
SHr=`grep $Cube $CompleteFileName |grep $member|grep START|cut -c 12,13`
SMin=`grep $Cube $CompleteFileName |grep $member|grep START |cut -c 15,16`
CHr=`grep $Cube $CompleteFileName |grep $member|grep COMPLETED|cut -c 12,13`
CMin=`grep $Cube $CompleteFileName |grep $member|grep COMPLETED|cut -c 15,16`
CalcHr=`grep $member $CompleteFileName |grep Script5|cut -c 12,13`
CalcHr=`grep $member $CompleteFileName |grep Script5|cut -c 12,13`
CalcMin=`grep $member $CompleteFileName |grep Script5|cut -c 15,16`
CalcDate=`grep $member $CompleteFileName |grep Script5|cut -c 9,10`
Script1=`grep $member $CompleteFileName|grep Script1|nawk -F'|' '{print $6}'|cut -f4 -d' '`
if [ -z $Script1 ]
then
(( FoundSwapOption +=1))
else
ReturnVal=$(RunTime $SDate $CDate $SHr $SMin $CHr $CMin)
Total=`expr $Total + $ReturnVal`
CalcVal=$(RunTime $SDate $CalcDate $SHr $SMin $CalcHr $CalcMin)
CalcTotal=`expr $CalcTotal + $CalcVal`
(( NotOptionSwap += 1 ))
if [ $NotOptionSwap -eq 3 ] #will exit after 3 previous runtime of the cube then break
then
break
fi
fi
done
AvgComplete=`expr $Total / $NotOptionSwap`
AvgCompleteHr=`expr $AvgComplete / 60`
AvgCompleteMin=`expr $AvgComplete % 60`
AvgCompleteHr=$(LessThan10 $AvgCompleteHr)
AvgCompleteMin=$(LessThan10 $AvgCompleteMin)
AvgCompleteRunTime="$AvgCompleteHr:$AvgCompleteMin"
EstCompleteMin=`expr $CurrentMin + $AvgCompleteMin`
EstCompleteHr=`expr $CurrentHr + $AvgCompleteHr`
if [ $EstCompleteMin -ge 60 ]
then
IncHr=`expr $EstCompleteMin / 60`
EstCompleteMin=`expr $EstCompleteMin % 60`
EstCompleteHr=`expr $EstCompleteHr + $IncHr`
fi
if [ $EstCompleteHr -ge 24 ]
then
EstCompleteHr=`expr $EstCompleteHr - 24`
EstCompleteMin=$(LessThan10 $EstCompleteMin)
EstCompleteHr=$(LessThan10 $EstCompleteHr)
EstCompleteTime="$EstCompleteHr:$EstCompleteMin *Next Day*"
else
EstCompleteMin=$(LessThan10 $EstCompleteMin)
EstCompleteHr=$(LessThan10 $EstCompleteHr)
EstCompleteTime="$EstCompleteHr:$EstCompleteMin"
fi
#Calculate Avg of 3 previous Calc Time
CalcAvg=`expr $CalcTotal / $NotOptionSwap`
CalcHrAvg=`expr $CalcAvg / 60`
CalcMinAvg=`expr $CalcAvg % 60`
#Estimate Hitcalc time
HitCalcEstMin=`expr $CurrentMin + $CalcMinAvg`
HitCalcEstHr=`expr $CurrentHr + $CalcHrAvg`
if [ $HitCalcEstMin -ge 60 ]
then
CalcIncHr=`expr $HitCalcEstMin / 60`
HitCalcEstMin=`expr $HitCalcEstMin % 60`
HitCalcEstHr=`expr $HitCalcEstHr + $CalcIncHr`
fi
if [ $HitCalcEstHr -ge 24 ]
then
HitCalcEstMin=$(LessThan10 $HitCalcEstMin)
HitCalcEstHr=$(LessThan10 $HitCalcEstHr)
HitCalcEstHr=`expr $HitCalcEstHr - 24`
HitCalcTime="$HitCalcEstHr:$HitCalcEstMin *Of the Next Day *"
else
HitCalcEstMin=$(LessThan10 $HitCalcEstMin)
HitCalcEstHr=$(LessThan10 $HitCalcEstHr)
HitCalcEstTime="$HitCalcEstHr:$HitCalcEstMin"
fi
if [ $HitCalc == "Yes" ]
then
if [ $CubeNameLength -lt 8 ]
then
# CubeName StartTime HitCalc AvgRunTime HitCalcAt EstTime
echo "$CubeName\t\t$CubeStartTime\t\t$AvgCompleteRunTime\t\t$HitCalc\t\t$HitCalcTime HitCalc\t\t$EstCompleteTime"
else
echo "$CubeName\t$CubeStartTime\t\t$AvgCompleteRunTime\t\t$HitCalc\t\t$HitCalcTime HitCalc\t\t$EstCompleteTime"
fi
else
if [ $CubeNameLength -lt 8 ]
then
echo "$CubeName\t\t$CubeStartTime\t\t$AvgCompleteRunTime\t\t$HitCalc\t\t$HitCalcEstTime\t\t\t$EstCompleteTime"
else
echo "$CubeName\t$CubeStartTime\t\t$AvgCompleteRunTime\t\t$HitCalc\t\t$HitCalcEstTime\t\t\t$EstCompleteTime"
fi
else
if [ $CubeNameLength -lt 8 ]
then
echo "$CubeName\t\t$CubeStartTime\t\t$AvgCompleteRunTime\t\t$HitCalc\t\t$HitCalcEstTime\t\t\t$EstCompleteTime"
else
echo "$CubeName\t$CubeStartTime\t\t$AvgCompleteRunTime\t\t$HitCalc\t\t$HitCalcEstTime\t\t\t$EstCompleteTime"
fi
fi
}
#################################################################
# Main
#################################################################
INDEX=0
#set -A ArrayCube $(ps -ef |grep build |grep essbase|awk '{print $11}'|sort -u)
set -A ArrayCube $(more /vframe/STR/bin/cubetest.txt |awk '{print $11}'|sort -u)
set -A NewArrayCube $(echo ${ArrayCube[*]}|sed 's/ /, /g')
echo "Current running cube: ${NewArrayCube[*]}\n"
echo "CubeName\tStartTime\tAvgRunTime\tHitCalc\t\tEstHitCalcAt\tEstCompleteTime"
echo "========\t=========\t==========\t=======\t\t============\t==============="
while [ ${ArrayCube[$INDEX]} ]
do
RC=$(Process ${ArrayCube[$INDEX]})
echo "$RC"
(( INDEX += 1 ))
done
****FINAL RESULT*****
Current running cube: EADtHR, EADtlP, EATir2, EUDtl, HAEastP, HAWLbrP, HAWPayP, MarAS02, MarASt, MarReDt, Rd_P2yr, Rd_Prior
CubeName StartTime AvgRunTime HitCalc EstHitCalcAt EstCompleteTime
EADtHR 07:44 01:32 No 08:57 09:16
EADtlP 07:50 07:39 No 11:11 15:29
EATir2 07:06 01:35 No 08:23 08:41
EUDtl 07:41 02:48 No 10:23 10:29
HAEastP 08:07 10:00 No 09:28 18:07
HAWLbrP 09:11 01:08 No 10:02 10:19
HAWPayP 09:01 03:23 No 11:51 12:24
MarAS02 07:40 04:42 No 12:11 12:22
MarASt 07:06 02:47 No 09:47 09:53
MarReDt 07:18 02:50 Yes 08:01 HitCalc 10:08
Rd_P2yr 08:02 02:08 Yes 08:57 HitCalc 10:10
Rd_Prior 07:44 02:06 No 08:33 09:50
Now I'm stuck at:
***Now users want to sort column 4 and 6
For column 4 sort Yes and No first then
column 6 sort largest time should be at the bottom.
I'm stuck with sorting request by users. ... I have read all question related to sort here but none fit with my problem.
I plan of attack is at the end of proccess function where
if [ $HitCalc == "Yes" ]
to put all answer in an array and sort within the array then print it out. ... Can anyone help me out
#####################################################
#The purpose of this script is to tell how long does
#it take for a specific cube to run,cube status,
#Estimate time hit calc and Estimate complete time.
#####################################################
. ~/.env
USAGE[1]="list_cube.sh R"
. $VF_BIN/script_header.sh
RunTime ( ) {
#For RunTime
#$1 = $SDate ; $3 = $SHr ; $4 = $SMin
#$2 = $CDate ; $5 = $CHr ; $6 = $CMin
#For Calc
#$1 = $SDate ; $3 = $SHr ; $4 = $SMin
#$2 = $CaclcDate ; $5 = $CalcHr ; $6 = $CalcMin
if [ $1 -eq $2 ]
then
StartTime=`expr \( $3 \* 60 \) + $4`
CompleteTime=`expr \( $5 \* 60 \) + $6`
expr $CompleteTime - $StartTime
else
StartTime=`expr \( \( 23 - $3 \) + $5 \) \* 60`
CompleteTime=`expr \( 60 - $4 \) + $6`
expr $StartTime + $CompleteTime
fi
}
LessThan10 ( ) {
#Hour compare
if [ $1 -lt 10 ]
then
echo "0$1"
else
echo "$1"
fi
}
Process ( ) {
CubeName="$1"
CubeNameLength=${#CubeName}
typeset -l Cube="$1.var"
FileName="build_cube.log"
CompleteFileName="$VF_LOG/$FileName"
Script5="Script5"
Script1="Script1"
Empty=""
typeset -i Total=0
typeset -i CalcTotal=0
typeset -i Avg=0
typeset -i CurHour=0
typeset -i NotOptionSwap=0
typeset -i NumOfRun=3
typeset -i FoundSwapOption=0
set -A Previous_idstring $(grep $Cube $CompleteFileName |tail -6|grep COMPLETED|nawk -F'|' '{print $2}'|sort -u)
Current_Id=`grep $Cube $CompleteFileName |tail -1|nawk -F'|' '{print $2}'`
CurrentHr=`grep $Cube $CompleteFileName |grep $Current_Id|grep START|cut -c 12,13`
CurrentMin=`grep $Cube $CompleteFileName |grep $Current_Id|grep START |cut -c 15,16`
CubeStatus=`grep $Current_Id $CompleteFileName|grep Script5|nawk -F'|' '{print $6}'|cut -f4 -d' '`
CubeStartTime="$CurrentHr:$CurrentMin"
#Check Calc status of current running cube
if [ -z $CubeStatus ]
then
HitCalc="No"
else
HitCalc="Yes"
HitCalcHr=`grep $Current_Id $CompleteFileName |grep Script5|cut -c 12,13`
HitCalcMin=`grep $Current_Id $CompleteFileName |grep Script5|cut -c 15,16`
HitCalcTime="$HitCalcHr:$HitCalcMin"
fi
for member in "${Previous_idstring[@]}"
do
SDate=`grep $Cube $CompleteFileName |grep $member|grep START|cut -c 9,10`
CDate=`grep $Cube $CompleteFileName |grep $member|grep COMPLETED|cut -c 9,10`
SHr=`grep $Cube $CompleteFileName |grep $member|grep START|cut -c 12,13`
SMin=`grep $Cube $CompleteFileName |grep $member|grep START |cut -c 15,16`
CHr=`grep $Cube $CompleteFileName |grep $member|grep COMPLETED|cut -c 12,13`
CMin=`grep $Cube $CompleteFileName |grep $member|grep COMPLETED|cut -c 15,16`
CalcHr=`grep $member $CompleteFileName |grep Script5|cut -c 12,13`
CalcHr=`grep $member $CompleteFileName |grep Script5|cut -c 12,13`
CalcMin=`grep $member $CompleteFileName |grep Script5|cut -c 15,16`
CalcDate=`grep $member $CompleteFileName |grep Script5|cut -c 9,10`
Script1=`grep $member $CompleteFileName|grep Script1|nawk -F'|' '{print $6}'|cut -f4 -d' '`
if [ -z $Script1 ]
then
(( FoundSwapOption +=1))
else
ReturnVal=$(RunTime $SDate $CDate $SHr $SMin $CHr $CMin)
Total=`expr $Total + $ReturnVal`
CalcVal=$(RunTime $SDate $CalcDate $SHr $SMin $CalcHr $CalcMin)
CalcTotal=`expr $CalcTotal + $CalcVal`
(( NotOptionSwap += 1 ))
if [ $NotOptionSwap -eq 3 ] #will exit after 3 previous runtime of the cube then break
then
break
fi
fi
done
AvgComplete=`expr $Total / $NotOptionSwap`
AvgCompleteHr=`expr $AvgComplete / 60`
AvgCompleteMin=`expr $AvgComplete % 60`
AvgCompleteHr=$(LessThan10 $AvgCompleteHr)
AvgCompleteMin=$(LessThan10 $AvgCompleteMin)
AvgCompleteRunTime="$AvgCompleteHr:$AvgCompleteMin"
EstCompleteMin=`expr $CurrentMin + $AvgCompleteMin`
EstCompleteHr=`expr $CurrentHr + $AvgCompleteHr`
if [ $EstCompleteMin -ge 60 ]
then
IncHr=`expr $EstCompleteMin / 60`
EstCompleteMin=`expr $EstCompleteMin % 60`
EstCompleteHr=`expr $EstCompleteHr + $IncHr`
fi
if [ $EstCompleteHr -ge 24 ]
then
EstCompleteHr=`expr $EstCompleteHr - 24`
EstCompleteMin=$(LessThan10 $EstCompleteMin)
EstCompleteHr=$(LessThan10 $EstCompleteHr)
EstCompleteTime="$EstCompleteHr:$EstCompleteMin *Next Day*"
else
EstCompleteMin=$(LessThan10 $EstCompleteMin)
EstCompleteHr=$(LessThan10 $EstCompleteHr)
EstCompleteTime="$EstCompleteHr:$EstCompleteMin"
fi
#Calculate Avg of 3 previous Calc Time
CalcAvg=`expr $CalcTotal / $NotOptionSwap`
CalcHrAvg=`expr $CalcAvg / 60`
CalcMinAvg=`expr $CalcAvg % 60`
#Estimate Hitcalc time
HitCalcEstMin=`expr $CurrentMin + $CalcMinAvg`
HitCalcEstHr=`expr $CurrentHr + $CalcHrAvg`
if [ $HitCalcEstMin -ge 60 ]
then
CalcIncHr=`expr $HitCalcEstMin / 60`
HitCalcEstMin=`expr $HitCalcEstMin % 60`
HitCalcEstHr=`expr $HitCalcEstHr + $CalcIncHr`
fi
if [ $HitCalcEstHr -ge 24 ]
then
HitCalcEstMin=$(LessThan10 $HitCalcEstMin)
HitCalcEstHr=$(LessThan10 $HitCalcEstHr)
HitCalcEstHr=`expr $HitCalcEstHr - 24`
HitCalcTime="$HitCalcEstHr:$HitCalcEstMin *Of the Next Day *"
else
HitCalcEstMin=$(LessThan10 $HitCalcEstMin)
HitCalcEstHr=$(LessThan10 $HitCalcEstHr)
HitCalcEstTime="$HitCalcEstHr:$HitCalcEstMin"
fi
if [ $HitCalc == "Yes" ]
then
if [ $CubeNameLength -lt 8 ]
then
# CubeName StartTime HitCalc AvgRunTime HitCalcAt EstTime
echo "$CubeName\t\t$CubeStartTime\t\t$AvgCompleteRunTime\t\t$HitCalc\t\t$HitCalcTime HitCalc\t\t$EstCompleteTime"
else
echo "$CubeName\t$CubeStartTime\t\t$AvgCompleteRunTime\t\t$HitCalc\t\t$HitCalcTime HitCalc\t\t$EstCompleteTime"
fi
else
if [ $CubeNameLength -lt 8 ]
then
echo "$CubeName\t\t$CubeStartTime\t\t$AvgCompleteRunTime\t\t$HitCalc\t\t$HitCalcEstTime\t\t\t$EstCompleteTime"
else
echo "$CubeName\t$CubeStartTime\t\t$AvgCompleteRunTime\t\t$HitCalc\t\t$HitCalcEstTime\t\t\t$EstCompleteTime"
fi
else
if [ $CubeNameLength -lt 8 ]
then
echo "$CubeName\t\t$CubeStartTime\t\t$AvgCompleteRunTime\t\t$HitCalc\t\t$HitCalcEstTime\t\t\t$EstCompleteTime"
else
echo "$CubeName\t$CubeStartTime\t\t$AvgCompleteRunTime\t\t$HitCalc\t\t$HitCalcEstTime\t\t\t$EstCompleteTime"
fi
fi
}
#################################################################
# Main
#################################################################
INDEX=0
#set -A ArrayCube $(ps -ef |grep build |grep essbase|awk '{print $11}'|sort -u)
set -A ArrayCube $(more /vframe/STR/bin/cubetest.txt |awk '{print $11}'|sort -u)
set -A NewArrayCube $(echo ${ArrayCube[*]}|sed 's/ /, /g')
echo "Current running cube: ${NewArrayCube[*]}\n"
echo "CubeName\tStartTime\tAvgRunTime\tHitCalc\t\tEstHitCalcAt\tEstCompleteTime"
echo "========\t=========\t==========\t=======\t\t============\t==============="
while [ ${ArrayCube[$INDEX]} ]
do
RC=$(Process ${ArrayCube[$INDEX]})
echo "$RC"
(( INDEX += 1 ))
done
****FINAL RESULT*****
Current running cube: EADtHR, EADtlP, EATir2, EUDtl, HAEastP, HAWLbrP, HAWPayP, MarAS02, MarASt, MarReDt, Rd_P2yr, Rd_Prior
CubeName StartTime AvgRunTime HitCalc EstHitCalcAt EstCompleteTime
EADtHR 07:44 01:32 No 08:57 09:16
EADtlP 07:50 07:39 No 11:11 15:29
EATir2 07:06 01:35 No 08:23 08:41
EUDtl 07:41 02:48 No 10:23 10:29
HAEastP 08:07 10:00 No 09:28 18:07
HAWLbrP 09:11 01:08 No 10:02 10:19
HAWPayP 09:01 03:23 No 11:51 12:24
MarAS02 07:40 04:42 No 12:11 12:22
MarASt 07:06 02:47 No 09:47 09:53
MarReDt 07:18 02:50 Yes 08:01 HitCalc 10:08
Rd_P2yr 08:02 02:08 Yes 08:57 HitCalc 10:10
Rd_Prior 07:44 02:06 No 08:33 09:50
Now I'm stuck at:
***Now users want to sort column 4 and 6
For column 4 sort Yes and No first then
column 6 sort largest time should be at the bottom.
I'm stuck with sorting request by users. ... I have read all question related to sort here but none fit with my problem.
I plan of attack is at the end of proccess function where
if [ $HitCalc == "Yes" ]
to put all answer in an array and sort within the array then print it out. ... Can anyone help me out