#!/bin/sh
################################################################################
##name : auto_awr.sh
##synopsis : create awr for two nodes for rac at the execute time
##author : qjm
##version : 2.1
################################################################################
################################################################################
##program var
################################################################################
v_awr_path=/backup/AWRreport
v_awr_user=awr
v_awr_pwd=awr
v_sid1=prod1
v_sid2=prod2
v_remote_path=/awr
v_remote_ip=10.10.0.3
v_remote_user=awr
v_remote_pwd=awr
################################################################################
##setup env
################################################################################
set_env()
{
v_who=`whoami`
v_bash_profile_path=`sed -n "/${v_who}/p" /etc/passwd|awk -F: '{print $6}'`
. ${v_bash_profile_path}/.bash_profile
cd ${v_awr_path}
v_begin=`sqlplus -silent /nolog <<END
conn ${v_awr_user}/${v_awr_pwd}
set pagesize 0 feedback off verify off heading off echo off
select snap_id from DBA_HIST_SNAPSHOT where to_char(begin_interval_time,'yyyymmddhh24')=to_char (sysdate-(3/24),'yyyymmddhh24') and rownum=1;
exit;
END`
v_end=`sqlplus -silent /nolog <<END
conn ${v_awr_user}/${v_awr_pwd}
set pagesize 0 feedback off verify off heading off echo off
select snap_id from DBA_HIST_SNAPSHOT where to_char(begin_interval_time,'yyyymmddhh24')=to_char (sysdate-(1/24),'yyyymmddhh24') and rownum =1;
exit;
END`
v_name1=`sqlplus -silent /nolog <<END
conn ${v_awr_user}/${v_awr_pwd}
set pagesize 0 feedback off verify off heading off echo off
select '${v_sid1}_'|| to_char(sysdate-(1/12),'yyyymmddhh24')||'.html' from dual;
exit;
END`
v_name2=`sqlplus -silent /nolog <<END
conn ${v_awr_user}/${v_awr_pwd}
set pagesize 0 feedback off verify off heading off echo off
select '${v_sid2}_'|| to_char(sysdate-(1/12),'yyyymmddhh24')||'.html' from dual;
exit;
END`
v_dbid=`sqlplus -silent /nolog <<END
conn ${v_awr_user}/${v_awr_pwd}
set pagesize 0 feedback off verify off heading off echo off
select dbid from V\\$database where rownum=1;
exit;
END`
}
################################################################################
##awr
################################################################################
f()
{
sqlplus "${v_awr_user}/${v_awr_pwd}"<<HERE
@$ORACLE_HOME/rdbms/admin/awrrpti.sql
$1
$2
$3
$4
$5
$6
$7
exit
HERE
}
################################################################################
##ftp
################################################################################
ftp_backup()
{
echo "ATTENTION : begin to upload awr report to remote ftp site"
export TAG=`date +%Y%m%d`
lftp -d <<EOF
open ${v_remote_ip}
user ${v_remote_user} ${v_remote_pwd}
lcd ${v_awr_path}
cd ${v_remote_path}
mput -c *${TAG}*
by
EOF
}
################################################################################
##begin excute
################################################################################
set_env
f html $v_dbid 1 1 $v_begin $v_end $v_name1
f html $v_dbid 2 1 $v_begin $v_end $v_name2
ftp_backup