Oracle Consulting Oracle Training Oracle Support Development
Home
Catalog
Oracle Books
SQL Server Books
IT Books
Job Interview Books
eBooks
Rampant Horse Books
911 Series
Pedagogue Books

Oracle Software
image
Write for Rampant
Publish with Rampant
Rampant News
Rampant Authors
Rampant Staff
 Phone
 919-335-6342
Oracle News
Oracle Forum
Oracle Tips
Articles by our Authors
Press Releases
SQL Server Books
image
image

Oracle Books

Oracle tuning

Oracle training

Oracle support

Remote Oracle

STATSPACK Viewer

Privacy Policy

  

 

ISBN 10: 
0-9776715-5-0
ISBN 13:
978-0977671557 
Library of Congress Number: 2007933681
312 pages
Perfect bind - 9x7
PD 807
Shelving:  Databases/Oracle Oracle In-Focus Series
#26

  Oracle Shell Scripting
Linux and UNIX Programming for Oracle

Jon Emmons

  

Retail Price $49.95 /  £34.95

Order now at 30% off and get access to the code depot! Only $30.95
(38% off)
       
Key Features   About the Author Table of Contents
Index Topics   Reader Comments Errata
       
-->

Shell scripting is necessary for automating a broad range of administration tasks on Oracle servers.  Many Oracle administrators and developers lack a strong system administration background and therefore manually perform these tasks at the cost of time, money and sustainability.

This book will discuss how to automate many of the common Oracle administration tasks as well as the methods necessary to automate site-specific tasks.  Special attention will be given to writing industry strength scripts which free the Oracle professional from daily maintenance tasks yet provide proper tracking and feedback to ensure the best possible operation.

With the expert techniques discussed in this book the reader will gain a functional knowledge of the building blocks of server-side shell scripting.  In addition to these techniques the reader will gain access to over 50 working scripts which can either be implemented as-is or be used as a basis for further scripts.

Topics include a background on shells and shell scripting, detailed step-by-step instructions on building shell scripts for administration tasks, how to tell when things are working right and how to effectively monitor the system for failures.

Shell scripting is one of the most universal tools on UNIX and Linux.  Shell scripting allows the administrator to combine any number of commands to be executed simultaneously or sequentially with a single script.  Sophisticated flow control allows shell scripts to react to conditions in the environment appropriately without the need for human intervention.  These scripts can be run manually to combine many steps into a single command.  Regular tasks can be automated through the use of 'cron' freeing the administrator from the burden of repeatedly executing scripts.


 

 

Key Features

• Understand what shell scripting can do for you

• Learn how to write your own shell scripts

• Learn important development and troubleshooting skills

• Expand your understanding of the UNIX and Linux environment

• Configure your shell to allow you to work more efficiently

• Save hours of development with over 50 working shell scripts to implement as-is or use as a basis for your own scripts

• Simplify administration by combining individual tasks into shell scripts

• Automate regular maintenance tasks

• Monitor system availability and performance

 

This book is intended for any Oracle professional who is running Oracle on Linux or UNIX.  The techniques discussed span all versions of Oracle and will be applicable by Oracle administrators, database developers, database programmers and anyone else who spends time at a UNIX prompt.

This book combines shell scripting techniques for beginner to expert with dozens of working scripts.  The skills discussed in this book will help the Oracle professional automate routine tasks freeing the administrator for more important duties.  The scripts included with this text will give the Oracle professional a fantastic head-start on automating their administration duties as well as being easily modifiable for any environment.

This combination of techniques and working scripts provide a complete sustainable solution for automating and improving any Oracle environment.

Why this book rocks:

Oracle Shell Scripting fulfills a unique niche for the Oracle Professional. While many books cover the installation and configuration of Oracle on UNIX and Linux the Oracle professional is then set adrift in their new environment. This book is their roadmap in that new environment.

Oracle Shell Scripting excels at elevating the skills and confidence of the UNIX novice. By focusing specifically on the tools needed by Oracle Professionals the tutorial portion of the book remains succinct and is complimented by the provided scripts saving the Oracle professional hours of work! This combination of how-to and scripts will render other 'pocket reference' books redundant while still entering at a lower price point than most version specific books.

Other books in this space are version-centric and fail to thoroughly address UNIX and Linux topics important to the Oracle professional. This version-agnostic book addresses the shell scripting skills necessary for the Oracle professional to master their UNIX environment and to simplify and automate their administration tasks.

About the Author:

 
Jon Emmons

Jon Emmons has many years of full-time experience running Oracle in a UNIX environment. His Oracle experience is reinforced by his many years as a UNIX system administrator. Jon has published extensively about Oracle on his website which continues to receive acclaim from the Oracle community.

Jon's work experience includes both industry and education. In addition to his technical abilities Jon has also been called upon to teach a college course in database management systems.
 

Table of Contents:

 

 

All examples are elaborated in detail and compared with the other techniques and tools introduced in the book.

 

Chapter 1: UNIX and Shell Scripting

Common Ground

UNIX and its many flavors

Why UNIX?

What is a shell?

sh bash and other shells

The UNIX kernel

Memory and swap  

Processes  

Files and file systems  

Why Shell Scripting?  

The shell Oracle and you  

When to script  

A warning about script bloat  

Building a shell script  

 

Chapter 2: Key Concepts  

Getting to your shell  

What shell am I in?  

Switching shells on-the-fly  

Differences between interactive and non-interactive modes  

Commands options arguments and input  

Shell Variables  

Conditions and if statements  

Loops  

Wildcards and Pattern Matching  

Relative and Absolute Paths  

Tilde the Short Way Home  

Permissions & Ownership  

 

Chapter 3: Setting up your environment  

Configuring your default shell  

Changing the Default Shell with usermod  

Changing Your Own Default Shell with the chsh Command  

Entering a shell  

bash Shell Login Behavior  

Bourne Shell Login Behavior  

Non-Interactive Shell Behavior  

Setting Your Command Prompt  

Basic Command Prompts  

Special Prompt Characters  

Variables and Commands in Prompts  

Setting Up the Binary Path  

The Manual Path  

The Library Path  

Aliases  

Keeping your scripts organized  

The .forward file  

Default Permissions and umask  

 

Chapter 4: Key tools  

man - The Online Manual Pages  

Text Editors  

Command-line and Graphical Editors – In Brief  

vi - The Visual Editor  

Manipulating Text  

Searching with grep  

More Complex Searches with egrep  

sed Text Substitution  

Breaking Out Columns with cut  

Using awk to Find Just What You Need  

Sort - Get Things in Order  

View the Beginning or End of a File  

Counting Characters Words and Lines with wc  

Managing Processes  

Stopping the Current Process  

Finding and Stopping Other Processes  

Viewing running processes with ps  

Ending running processes with the kill command  

pgrep and pkill  

Examining how long a command takes  

Job Control - Running Jobs in the Background  

Making sure things keep running with nohup  

File and Directory Ownership and Permissions  

Managing the owner and group of a file  

Managing File Permissions  

How Permissions Affect Directories  

Securing Important Files  

Manipulating Input and Output  

Redirecting Standard Input  

Redirecting Standard Output and Standard Error  

Linking Output to Input with Pipes  

Performing Math with expr  

 

Chapter 5: Simple Scripting  

Setting Up Your First Script  

The Significance of the Shebang  

Commenting Your Script  

Variables  

Variable Scope  

Variable Names  

Using Arguments in Your Script  

Prompting for Input  

Debugging Shell Scripts  

Place Temporary Markers in the Script  

Echo Variables to the Display  

Starting the Script in Debug Mode  

 

Chapter 6: Interacting with SQL*Plus  

Calling SQL Scripts from Shell Scripts  

Embedding SQL within a Shell Script  

Prompting for a password  

Reading a Password from a File  

Running shell commands from SQL*Plus  

Passing variables into SQL*Plus  

SQL Script Arguments  

Shell Variables and Embedded SQL  

Getting Information Out of SQL*Plus  

 
 Chapter 7: Making Decisions  

Conditional Expressions  

Comparing Numbers  

Comparing Text  

Checking Files  

Combining Comparisons  

Making Simple Decisions with if and else  

Secondary Checks with elif  

Choosing from a list with case  

The while Loop  

The for Loop  

Breaking Out of Loops  

Nesting Loops  

 

Chapter 8: Checking and Reporting Results  

The Exit Status: The Unseen Result  

Setting the Exit Status of a Shell Script  

Setting the Exit Status for SQL*Plus  

Scanning Logs for Output  

Checking the Output of Commands  

 

Chapter 9: Making the Shell Behave  

Listing multiple commands on one line  

Conditional Execution  

Listing Long Commands on Multiple Lines  

Backslash as an Escape Character  

Single Quotes  

Double Quotes  

Back Quotes  

Exit a Shell Script Anytime  

 

Chapter 10: Making Scripts Run Automatically  

Scheduling Repeating Tasks with Cron  

The cron Daemon  

crontab Command Options  

The Format of the crontab File  

crontab Entries  

Scheduling One-Time Tasks with at  

Performing Tasks On Login  

 

Chapter 11: Reaching Further  

Transferring Files between Systems  

sftp - Secure FTP  

scp - Secure Copy  

Executing commands on another system  

Keep Directories in Sync with rsync  

Getting Past the Password Problem  

Executing Commands with Another User’s Permissions  

Using su to become Another User  

Emailing from scripts  

Emailing System Users and the .forward File  

Emails from cron and at Jobs  

The mail command  

 

Chapter 12: Oracle Database Maintenance  

Monitoring and Maintaining the Alert Log  

Checking for Errors in the Alert Log  

Rotating the Alert Log  

Finding and removing old dump files  

Monitoring Tablespace Usage  

Clean Up Old Statspack Data  

Check Certain Database Accounts are Locked  

Cleaning Old Data Out of Tables  

Execute a SQL Script on Every Database  

Copy the TNSNames File to a List of Systems  

 

Chapter 13: Backup Scripts  

Cold Backups without RMAN  

Hot Backups without RMAN  

Hot Backups with RMAN  

Database and Schema Export  

 

Chapter 14: Oracle Database Monitoring  

Listener Availability  

Database Availability  

Monitor Free Space within Tablespaces  

Table is Writeable Readable or Other Specific SQL  

Check for Invalid Objects  

 

Chapter 15: Oracle Application Server  

Starting and Stopping Oracle Application Server  

Cleaning Up Web Server Log Files  

Starting and Stopping the Application Server Console  

Check Running OPMN Processes  

 

Chapter 16: Monitoring the System  

Checking the System Log  

Monitoring disk space  

Find the Size of a Directory  

Monitoring system load  

Save Load Averages in Oracle  

Gathering CPU Usage Statistics from sar  

Synchronize a Directory on Several Systems  

 

Chapter 17: Windows Scripting  

What’s Different in Windows?  

Database Exports  

RMAN backups  

Running a SQL Script  

Other Scripting Options for Windows  

Scheduling Scripts in Windows  

From the series Editor:


Index Topics:

$

$ORACLE_HOME

$ORACLE_SID

$SHELL 

 

&

&& 

 

.

.bash_login

.bash_profile 

.bashrc

.forward

.login

.profile

.sh extension 

 

/

/q 

 

?

? variable 

 

A

-a 

absolute path

access permissions

alert log 

alias 

alias command

apachectl command 

arguments

at command 

atq command 

atrm command 

authorized_keys 

awk 

 

B

back quotes 

backquote

backslash 

backtick

bash

batch mode

bg command

bind variables 

Bourne 

Bourne Again  

Bourne-Again  

break keyword 

break statement 

bye 

 

C

-c 

case statement 

cat command 

cd 

chgrp 

chgrp command

chmod 

chmod command 

chown 

chown command

chsh command

conditional expression 

control-c

control-d 

cp command 

cron 

crontab 

crontab command 

cut 

cut command

Cygwin 

 

D

-d 

–d

daemon 

date command 

db_host_file 

dba_objects 

dba_users

dbstart command 

dcmctl 

default shell 

del command 

--delete 

df command 

do keyword 

done keyword 

double quotes 

du command 

 

E

-e 

–e

echo

echo command

edit command

EditPlus

egrep 

elif 

env command

environmental variables

EOF 

-eq 

--exclude 

execute permission

exit command 

exit condition 

exit status 

exp command 

exp_arguments 

export command

expr command 

F

-f

-F

–f 

fg command

fi 

find command 

for loop 

 

G

-ge 

get 

goto 

grave symbols

grep 

grep command

GRID controller 

groups command

-gt

gzip 

 

H

hashbang 

head

help 

home directory

host command 

hostname command 

 

I

if statement

imp command 

in keyword 

interactive mode

 

J

job scheduler 

jobs command

 

K

kernel

kill command 

Korn 

 

L

-l

lcd 

-ld

LD_LIBRARY_PATH

-le 

load average 

--login

lpwd 

ls 

ls -l

lsnrctl 

-lt

 

M

-m

mail command 

mailx command 

man command 

man page 

mv command 

 

N

–n

-ne 

nested loops 

nohup command

non-interactive mode

Notepad 

 

O

-o 

opmn 

opmnctl 

Oracle Application Server 

Oracle Discoverer 

Oracle Process Manager and Notification 

oraenv command 

 

P

-p

-P 

parent process ID

passphrase 

PATH

pgrep command 

pkill command 

popular wildcards

PPID

present working directory 

process ID 

ps command 

PS 

put 

PuTTY

pwd

 

Q

quit 

 

R

-r 

read command 

read permission

redirected input 

regular expressions 

relative path 

rlogin

rm 

rm command

RMAN 

rmdir 

root directory 

rsync 

 

S

-s 

-S 

sa  command 

sar utility 

Scheduled Task Wizard 

scp 

scp command 

script parameters 

secure shell protocol

sed 

set command 

setgid

setuid

sftp 

shebang 

shift command 

SIGHUP 

SIGINIT 

SIGKILL 

SIGTERM 

Simon Tatham

single quotes 

Single UNIX Specification  

slash 

sort command 

spool 

SQL*Plus

sqlplus 

sqlplus command

SSH

ssh-keygen 

standard error output 

standard input 

standard output

statspack 

sticky bit

STIME

su command 

substitution variables 

 

T

tab 

tablespace usage 

tail 

telnet 

then clause 

tilde 

time command

tnsnames.ora 

touch command

 

U

-u 

-U

UID

umask

unalias command

unset command 

uptime command 

usermod 

 

V

-v 

v$instance 

vi 

Visual Basic 

vmstat command

-vx 

 

W

-w

wall clock time

wc

which command

while loop

whoami command 

write permission

 

X

-x 

 

Reviews:

 

Very Informative., December 5, 2007

By Mike Bennett "real name"


I'm a veteran Oracle Database Administrator and most of my work is on Unix systems so I wasn't sure how much information in this book would be useful to me. I was pleasantly surprised to find what a wide range of scripting tips and techniques this manual provides. I was impressed by the fact that the author didn't just describe HOW to do something, but also explained WHY a particular approach was taken.

I also like the fact that the scripts given aren't just contrived samples, but are practical and useful as given. This information will definitely help simplify some of my routine tasks and provide me with timely information about the environments and systems I work with. The author also pointed out how to go beyond what was provided in the book by suggesting ways the examples might be modified. I've already taken advantage of that with a script I helped one of my clients develop.


It’s a lot better than parsing through thick UNIX encyclopedias or cycling through fragmented online material..as an OCP 10g/9i DBA, I still feel like there are not enough practical day-to-day guides like this one for junior/mid/senior-level administrators, since over half our work is directly/indirectly connected to the shell.

This book has helped me impress my colleagues and boss..I originally browsed through it at Border’s (and found myself sitting on the ground with a notepad scrambling to copy as much as possible). of course, then I realized I had to have it, so I bought it online. I knew the publisher was a trustworthy source because I’m always using Don Burleson’s DBA tips online.. this author’s approach is easy-to-follow and concise; yet it’s a thorough guide that is like a catalyst for your own creativity…it has made me look forward to extracting the power of the shell.

By, Prashant


February 8, 2008  

Great book!
A well written book. A great way to learn shell scripting. Relevant and useful examples throughout the book (downloadable code).

By  Jolly - See all my reviews


From the Editor:  Donald K. Burleson

As the series editor for this book, I recognize the need for Oracle professionals to "think outside the box", and a good command of UNIX and Linux command syntax and scripting is critical for the effective management of complex server environments.  As a working Oracle professional I'm always using Oracle shell scripts to perform external management tasks, and it is very difficult for beginners to grasp the cryptic syntax and language structures of the UNIX shell command languages.

 

During the production of this book I insisted that each and every topic be clear and understandable, with a focus on providing a clear understanding of the functionality of Oracle scripting.  I think that Jon and Zach met their mandate, and I'm especially pleased with the code depot of working Oracle scripts.

 

 

 

Errata:

Page 213 - There is a code named statspackError! Bookmark not defined._purge.sh

I believe the proper name of the script is statspack_purge.sh

 

   

 Copyright © 1996 -2023 by Burleson. All rights reserved.


Oracle® is the registered trademark of Oracle Corporation. SQL Server® is the registered trademark of Microsoft Corporation. 
Many of the designations used by computer vendors to distinguish their products are claimed as Trademarks