728x90
CODE:
-
#!/bin/bash
-
################################################################################
-
# Script Name: check_alert_log.sh #
-
# #
-
# Oracle Shell Scripting, Chapter 12 #
-
# #
-
# Usage: check_alert_log.sh SID #
-
# #
-
# Notes: If ORACLE_SID is set in the environment then the SID argument is #
-
# optional #
-
# #
-
# This script is from the book Oracle Shell Scripting by Jon Emmons #
-
# Copyright 2007 Rampant TechPress www.rampant-books.com #
-
# #
-
# DISCLAIMER: Every environment is different. This scrip may need to be #
-
# customized before use and any script should be tested in a #
-
# development environment before being used in production. #
-
################################################################################
-
-
# Add /usr/local/bin to the PATH variable so the oraenv command can be found
-
PATH=$PATH:/usr/local/bin; export PATH
-
-
# If a SID is provided as an argument it will be set and oraenv run
-
# otherwise we will use the current SID. If no SID is set or provided
-
# an error message is displayed and the script exits with a status of 1
-
if [ $1 ]
-
then
-
ORACLE_SID=$1
-
ORAENV_ASK=NO
-
. oraenv
-
else
-
if [ ! $ORACLE_SID ]
-
then
-
echo "Error: No ORACLE_SID set or provided as an argument"
-
exit 1
-
fi
-
fi
-
-
# Set the ORACLE_BASE variable
-
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
-
-
cd $ORACLE_BASE/admin/$ORACLE_SID/bdump
-
-
# Copy the current alert log into a temporary file and empty the original
-
cp alert_$ORACLE_SID.log alert_$ORACLE_SID.log.temp
-
cp /dev/null alert_$ORACLE_SID.log
-
-
# Check the copy in the temporary file for ORA- errors
-
grep 'ORA-' alert_$ORACLE_SID.log.temp> /dev/null
-
# If found, email the Oracle user with the contents of the alert log
-
if [ $? = 0 ]
-
then
-
mail -s "$ORACLE_SID database alert log error" oracle <\
-
alert_$ORACLE_SID.log.temp
-
fi
-
-
# Move the contents of the temp file onto the permanent copy of the log
-
# and remove the temp file.
-
cat alert_$ORACLE_SID.log.temp>> alert_$ORACLE_SID.log.1
-
rm alert_$ORACLE_SID.log.temp
CODE:
-
#!/bin/bash
-
################################################################################
-
# Script Name: check_filesystem_space.sh #
-
# #
-
# Oracle Shell Scripting, Chapter 16 #
-
# #
-
# Usage: check_filesystem_space.sh #percent /filesystem /filesystem2 #
-
# #
-
# Notes: You can specify as many file systems as you would like by adding #
-
# arguments. #
-
# #
-
# This script is from the book Oracle Shell Scripting by Jon Emmons #
-
# Copyright 2007 Rampant TechPress www.rampant-books.com #
-
# #
-
# DISCLAIMER: Every environment is different. This scrip may need to be #
-
# customized before use and any script should be tested in a #
-
# development environment before being used in production. #
-
################################################################################
-
-
# Set the percentage used at which you would like to be alerted
-
# Use argument 1 if provided or use a given default.
-
if [ ! $2 ]
-
then
-
echo "No filesystems specified."
-
echo "Usage: check_filesystem_space.sh 90 / /u01"
-
exit 1
-
fi
-
-
max=$1
-
-
# Email addresses are listed here separated by commas
-
mail_to='root, oracle'
-
-
tempfile=/tmp/check_filesystem_space.txt
-
-
alert=n
-
-
# Take each percentage from the df command and check it against the defined max
-
# Some platforms may not require (or even recognize) the -P option for df
-
while [ $2 ]
-
do
-
percent=`df -P $2 | tail -1 | awk '{ print $5 }' | cut -d'%' -f1`
-
-
if [ $percent -ge $max ]
-
then
-
alert=y
-
break
-
fi
-
-
shift
-
-
done
-
-
# If a partition was above the threshold send a message with df output
-
if [ ! $alert = 'n' ]
-
then
-
df -k> $tempfile
-
mail -s "Disk usage above $max% on `hostname`" $mail_to <$tempfile
-
rm $tempfile
-
fi
CODE:
-
#!/bin/bash
-
################################################################################
-
# Script Name: check_for_invalid_objects.sh #
-
# #
-
# Oracle Shell Scripting, Chapter 14 #
-
# #
-
# Usage: check_for_invalid_objects.sh SID #
-
# #
-
# Notes: If ORACLE_SID is set in the environment then the SID argument is #
-
# optional. #
-
# #
-
# This script is from the book Oracle Shell Scripting by Jon Emmons #
-
# Copyright 2007 Rampant TechPress www.rampant-books.com #
-
# #
-
# DISCLAIMER: Every environment is different. This scrip may need to be #
-
# customized before use and any script should be tested in a #
-
# development environment before being used in production. #
-
################################################################################
-
-
# If a SID is provided as an argument it will be set and oraenv run
-
# otherwise we will use the current SID. If no SID is set or provided
-
# an error message is displayed and the script exits with a status of 1
-
if [ $1 ]
-
then
-
ORACLE_SID=$1
-
ORAENV_ASK=NO
-
. oraenv
-
else
-
if [ ! $ORACLE_SID ]
-
then
-
echo "Error: No ORACLE_SID set or provided as an argument"
-
exit 1
-
fi
-
fi
-
-
# Define the location of the temporary file this script will use
-
tempfile=/tmp/check_for_invalid_objects_$ORACLE_SID.txt
-
-
# Start sqlplus and connect as sysdba
-
sqlplus -S "/ as sysdba" <<EOF1> /dev/null
-
-
define exit_status = 0
-
-
column xs new_value exit_status
-
-
select 1 as xs from dba_objects where status!='VALID';
-
-
exit &exit_status
-
-
EOF1
-
-
# If the exit status of sqlplus was not 0 then we will lauch sqlplus
-
# to run utlrp.sql and send an email
-
if [ $? != 0 ]
-
then
-
-
sqlplus -S "/ as sysdba" <<EOF2> $tempfile
-
-
set pagesize
-
-
select count(*) || ' invalid objects found. Running utlrp.'
-
from dba_objects where status!='VALID';
-
-
set pagesize 32
-
-
@?/rdbms/admin/utlrp.sql
-
-
EOF2
-
-
mail -s "Invalid objects found in $ORACLE_SID" oracle <$tempfile
-
-
fi
-
-
rm $tempfile
CODE:
-
#!/bin/bash
-
################################################################################
-
# Script Name: rman_hot_backup.sh #
-
# #
-
# Oracle Shell Scripting, Chapter 13 #
-
# #
-
# Usage: rman_hot_backup.sh SID #backuplevel #
-
# #
-
# Notes: If not specified the backup level will default to 1 and the SID #
-
# will be taken from the environmental variable ORACLE_SID #
-
# #
-
# This script is from the book Oracle Shell Scripting by Jon Emmons #
-
# Copyright 2007 Rampant TechPress www.rampant-books.com #
-
# #
-
# DISCLAIMER: Every environment is different. This scrip may need to be #
-
# customized before use and any script should be tested in a #
-
# development environment before being used in production. #
-
################################################################################
-
-
# Add /usr/local/bin to the PATH variable so the oraenv command can be found
-
PATH=$PATH:/usr/local/bin; export PATH
-
-
# A second argument can be provided to give a backup level
-
# if the backup level is not provided a level 0 backup will be performed.
-
if [ $2 ]
-
then
-
backup_level=$2
-
else
-
backup_level=0
-
fi
-
-
# If a SID is provided as an argument it will be set and oraenv run
-
# otherwise we will use the current SID. If no SID is set or provided
-
# an error message is displayed and the script exits with a status of 1
-
if [ $1 ]
-
then
-
ORACLE_SID=$1
-
ORAENV_ASK=NO
-
. oraenv
-
else
-
if [ ! $ORACLE_SID ]
-
then
-
echo "Error: No ORACLE_SID set or provided as an argument"
-
exit 1
-
fi
-
fi
-
-
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
-
-
admin_dir=$ORACLE_BASE/admin/$ORACLE_SID; export admin_dir
-
-
backup_user=backup_admin
-
backup_user_pw=`cat $ORACLE_BASE/admin/$ORACLE_SID/pw/$backup_user.pw`
-
-
catalog_user=rman
-
catalog_user_pw=`cat $ORACLE_BASE/admin/$ORACLE_SID/pw/$catalog_user.pw`
-
-
# Backup variables. Set the backup_dir to the appropriate
-
# location for your site.
-
log_file=$admin_dir/scripts/rman_hot_backup_$ORACLE_SID.log
-
-
# This adds some text and a date stamp to the beginning of the backup log
-
echo "Beginning hot backup of $ORACLE_SID"> $log_file
-
date>> $log_file
-
-
rman target=$backup_user/$backup_user_pw \
-
catalog=$catalog_user/$catalog_user_pw@rman <<EOF>> $log_file
-
-
backup incremental level=$BACKUP_LEVEL database plus archivelog delete input;
-
-
delete noprompt obsolete;
-
-
quit;
-
-
EOF
-
-
# Add some end text and timestamp to the log file
-
echo "Finished hot backup of $ORACLE_SID">> $log_file
-
date>> $log_file
-
-
# Email appropriate folks only if an error is found
-
grep "ORA-" $log_file> /dev/null
-
ora_err=$?
-
grep "RMAN-" $log_file> /dev/null
-
rman_err=$?
-
if [ $ora_err = 0 -o $rman_err = 0 ]
-
then
-
mail -s "$ORACLE_SID Hot Backup Problem" oracle <$log_file
-
fi
CODE:
-
#!/bin/bash
-
################################################################################
-
# Script Name: dba_schema_export.sh #
-
# #
-
# Oracle Shell Scripting, Chapter 13 #
-
# #
-
# Usage: dba_schema_export.sh SID schema #
-
# #
-
# Notes: This script must be run as a user who can connect as sysdba #
-
# #
-
# This script is from the book Oracle Shell Scripting by Jon Emmons #
-
# Copyright 2007 Rampant TechPress www.rampant-books.com #
-
# #
-
# DISCLAIMER: Every environment is different. This scrip may need to be #
-
# customized before use and any script should be tested in a #
-
# development environment before being used in production. #
-
################################################################################
-
-
exp_arguments='USERID="/ as sysdba" BUFFER=10485760 FULL=N'
-
-
# Add /usr/local/bin to the PATH variable so the oraenv command can be found
-
PATH=$PATH:/usr/local/bin; export PATH
-
-
ORACLE_SID=$1
-
ORAENV_ASK=NO
-
. oraenv
-
-
ORACLE_BASE=/u01/app/oracle
-
-
schema=$2
-
-
log_file=$ORACLE_BASE/admin/$ORACLE_SID/scripts/dba_schema_export_$ORACLE_SID_$schema.log
-
-
exp_arguments="$exp_arguments OWNER=$schema"
-
-
# If a third argument was specified use it as the file destination
-
if [ $3 ]
-
then
-
exp_arguments="$exp_arguments FILE=$3"
-
else
-
exp_arguments="$exp_arguments FILE="$ORACLE_SID"_"$schema"_export.dmp"
-
fi
-
-
# Put some informational text in the log file
-
echo "Starting export `date`"> $log_file
-
echo "Exporting with the following arguments: $exp_arguments">> $log_file
-
-
# Run the export with the arguments provided and capture the result code
-
exp $exp_arguments>> $log_file 2>&1
-
-
exp_result=$?
-
-
echo "Completed export `date`">> $log_file
-
-
# Email appropriate folks only if an error is found
-
if [ exp_result != 0 ]
-
then
-
mail -s "$ORACLE_SID Export Problem" oracle <$log_file
-
fi
CODE:
-
@echo off
-
REM Script Name: run_report.bat
-
REM
-
REM Oracle Shell Scripting, Chapter 17
-
REM
-
REM Usage: run_report.sh
-
REM
-
REM Notes: The variables sould be set to the appropriate credentials and
-
REM script location for your script.
-
REM
-
REM This script is from the book Oracle Shell Scripting by Jon Emmons
-
REM Copyright 2007 Rampant TechPress www.rampant-books.com
-
REM
-
REM DISCLAIMER: Every environment is different. This scrip may need to be
-
REM customized before use and any script should be tested in a
-
REM development environment before being used in production.
-
-
REM Set the variables below with your connection and script information
-
REM All output from sqlplus will be sent to the output file
-
set USERNAME=scott
-
set PASSWORD=tiger
-
set SID=ossw
-
set SQL_SCRIPT=D:\oracle\product\10.1.0\admin\common\report.sql
-
set OUTPUT_FILE=D:\oracle\product\10.1.0\admin\common\logs\report.txt
-
-
REM run sqlplus in silent mode with the parameters set above
-
sqlplus -S %USERNAME%/%PASSWORD%@%SID% @%SQL_SCRIPT%> %OUTPUT_FILE%
-
-
@echo on
'데이터베이스 > 오라클' 카테고리의 다른 글
[펌] 유용한 오라클 쿼리 정리 (0) | 2011.03.07 |
---|---|
오라클 정규식 사용 팁 (0) | 2010.11.05 |
Oracle DBA Scripts and Tips (0) | 2010.09.28 |
오라클 튜닝 & 유지보수 관련정리 (0) | 2010.09.28 |
소계 & 총계 구하는 SQL (ROLLUP) (0) | 2010.08.16 |