[shell] execute remote Script自動生成oracle awr report並mail出來

tolilong發表於2016-03-09
shell執行遠端Script自動生成awr report並mail出來

1.remote machine shell script
[mon@topaz source]$ more gen_oracle_awr 
#!/bin/bash
export ORACLE_BASE=/u01/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_SID=wlcsp
AWRHOME=/home/mon/awr

#interval=8
#echo $ORACLE_SID
maxmin=`$ORACLE_HOME/bin/sqlplus -s /nolog << EOF # >> /home/mon/log/gen_oracle_awr.log #if general output to log,the maxmin will not get the value.
conn / as sysdba;
set heading off pagesize 0 feedback off verify off echo off;
select max(snap_id),min(snap_id) from dba_hist_snapshot where begin_interval_time>=sysdate-1 and begin_interval_time<=sysdate-1+8/24;
exit;
EOF`

#if [ -z "$maxmin" ]; then
#   echo "no rows returned from database"
#   exit 0
#else
#   echo $maxmin
#fi

max=`echo $maxmin | awk '{print $1}'`
min=`echo $maxmin | awk '{print $2}'`
#echo $max
#echo $min

rm -rf $AWRHOME/*

$ORACLE_HOME/bin/sqlplus -s /nolog << EOF >> /dev/null
conn / as sysdba;
@?/rdbms/admin/awrrpt.sql;
html
2
$min
$max
$AWRHOME/awrrpt_1_${min}_${max}.html
EOF

#cat $AWRHOME/awrrpt_1_${min}_${max}.html | mutt -s "$ORACLE_SID Database AWR Report" -e "set content_type=text/html" tolilong@163.com -a $AWRHOME/awrrpt_1_${min}_${max}.html

2.local machine script
[mon@oracle6 source]$ more gen_remote_oracle_awr 
#!/bin/bash
TAWRHOME=/home/mon/awr/topaz
ssh mon@topaz /home/mon/source/gen_oracle_awr
scp mon@topaz:/home/mon/awr/* $TAWRHOME/

FILE=`ls -tr $TAWRHOME/* | tail -1`
cat $FILE | mutt -s "Topaz Database AWR Report" -e "set content_type=text/html" tolilong@163.com -a $FILE

3.add crontab job
###############general remote awr################################
16 15 * * * /home/mon/source/gen_remote_oracle_awr > /dev/null 2>&1

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24237320/viewspace-2052133/,如需轉載,請註明出處,否則將追究法律責任。

相關文章