Shell Scripting for Oracle DBA

Shell scripting is really important for Oracle DBA. most of the repetitive work can be done with the help of Shell Script. Recurring tasks, schedule jobs, monitoring, Automating can be automated navigator with the help of Shell Script.

Following video full explain you for creation of Shell Script, permission for Shell Script and scheduling of shell script with the help of crontab.

Shell variable

variable ="Hello"
echo $variable


read input from user.


#!/bin/sh

# Author : Ankush Thavali
# Copyright (c) blognow.com
# Script follows here:

echo "What is your name?"
read PERSON
echo "Hello, $PERSON


Defining Array Values

#!/bin/sh

NAME[0]="testdb"
NAME[1]="prim"
NAME[2]="pdbprim"
NAME[3]="checkdb"
NAME[4]="ndb"
echo "First Index: ${NAME[0]}"
echo "Second Index: ${NAME[1]}"


For loop

#!/bin/sh
for i in 1 2 3 4 5
do
echo "Looping ... number $i"
done


While Loop


#!/bin/sh
INPUT_STRING=hello
while [ "$INPUT_STRING" != "bye" ]
do
echo "Please type something in (bye to quit)"
read INPUT_STRING
echo "You typed: $INPUT_STRING"
done


Command line argument

#!/bin/sh

echo "File Name: $0"
echo "First Parameter : $1"
echo "Second Parameter : $2"


Checking no of argument passed


sh hello.sh hello-world
# I am passing hello-world as argument in command line which will b considered as 1 argument
if [ $# -eq 1 ]
then
echo $1
else
echo "invalid argument please pass only one argument "
fi

Script to check no of processess running on databases.


. /dba/admin/common/kshell/setsid qmsmp
current_date=$(date +%Y-%m-%d)
sqlplus -S "/ as sysdba " <<EOF >/dba/admin/qmsmp/alter/process_count_qmsmp.log

set lines 12345 pages 12345;
col username for a30;
col status for a30;


select name,open_mode from v\$database;
select resource_name, current_utilization ,max_utilization ,INITIAL_ALLOCATION Allocated from v\$resource_limit where resource_name in ('processes', 'sessions');
EOF
mailx -s "Current:Processes & Session counts!! DB Name: QMSMP : $current_date EST " abc@abc.com,abc@abc.com < /dba/admin/qmsmp/alter/process_count_qmsmp.log

Share and Enjoy !

0Shares
0 0 0

Recommended For You

ankushthavali

About the Author: ankushthavali

Leave a Reply

Your email address will not be published. Required fields are marked *