ITPub博客

首页 > Linux操作系统 > Linux操作系统 > [shell] execute remote Script自动生成oracle awr report并mail出来

[shell] execute remote Script自动生成oracle awr report并mail出来

原创 Linux操作系统 作者:tolilong 时间:2016-03-09 20:17:35 0 删除 编辑
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博客 ” ,链接:https://blog.itpub.net/24237320/viewspace-2052133/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2010-07-13

  • 博文量
    406
  • 访问量
    1208693