当我们用spool log的方式记录RMAN的输出,计算该输出里所有Elapsed Time的时间和:
Here is Calculate Time shell script :
=========================================================
#!/bin/sh
logfile=$1
grep elapsed $logfile |awk -F " " '{print $NF}' > /tmp/timeList;
file=/tmp/timeList
rm /tmp/1.log
touch /tmp/1.log
for line in $(<$file);
do
hour=$(echo $line |cut -d ':' -f 1);
minute=$(echo $line |cut -d ':' -f 2);
second=$(echo $line |cut -d ':' -f 3);
Time=$(( 10#${hour}*3600 + 10#${minute}*60 + 10#${second} ))
echo $Time >> /tmp/1.log
done
sum=$(cat /tmp/1.log |awk '{sum+=$1}; END {print sum}')
echo "sum is ${sum}s "
hor=$(( ${sum}/3600 ))
min=$(( (${sum}-${hor}*3600)/60 ))
sec=$(( ${sum}-${hor}*3600-${min}*60 ))
showTime="${hor}:${min}:${sec}"
echo "Use time is $showTime ( ${sum}s ) for $logfile . "
=========================================================
Output for it will be :
sum is 7s Use time is 0:0:7 ( 7s ) for /tmp/RMAN_backup.log