#!/bin/sh
## Please run by User oinstall.

## ora_idx_rebuild.sh ver 0.01 ================================================
source /etc/bashrc

mailaddress='user@your domain .jp'  ## Admin's mail address
MachineId=`hostname`
dbuser=test
dbpw=@test123
tnsname=testdb
script=/tmp/idxrebuild_and_analyze.sql
##=============================================================================

## BEGIN BLOCK 1.2 : MailOnGood()----------------------------------------------
MailOnGood ()
{
    Today=`date '+%Y/%m/%d'`
    Time=`date '+%T'`
    MailTo=$mailaddress
    echo "===================
$0
$Today
$Time

HostName: $MachineId
Database: ${ORACLE_SID}
===================
$message
" | mail -s "ORACLE AUTO index-rebuild & Analyze" $MailTo
}
## ENDBLOCK 1.2----------------------------------------------------------------


## BEGIN BLOCK 1 : ORACLE Status SQL no1 --------------------------------------
CHK=`
sqlplus $dbuser/$dbpw$tnsname << Eof 2>&1
    @ $script
    exit
Eof`

## END BLOCK 1 ----------------------------------------------------------------

MailOnGood
exit 0
