Question: What are the best practices for using OS
shell scripts? I'm charged with managing all the oracle crontab entries on
a 16-way Linux server, and we use a variety of shell like ksh, csh and bash.
What are the best practices for using Oracle shell scripts?
Answer: There is an excellent overview of
Oracle shell scripting best practices in book "Oracle
Shell Scripting" by Jon Emmons, and see the book "Oracle
Job Scheduling" for an overview of using dbms_scheduler for executing
external shell scripts within Oracle.
See these important notes on color coding your prompt,
OS prompt best practices, and making the prompt include the host name,
instance name and current directory.
DBA's have been using cron jobs to schedule external Oracle
jobs since the early 1990's, long before Oracle introduced their own job
scheduling functionality (dbms_job and dbms_scheduler).
External job include anything that interfaces with OS files such as:
Server-side monitoring (e.g. vmstat to Oracle capture
Alert log scanning
Trace and dump file management
Archived redo log management
Automated external batch jobs that interface with other
The standards and best practices for shell scripting vary
widely between shops, but in general they falls into these areas:
Shell script standards - It's always best to
standardize on a shell. Historically, most shops used Korn shell
(ksh), but today many shops use the Bourne Again shell (bash).
Job invocation best practices - After 10gr2
introduced secure external job scheduling with dbms_scheduler (with
the create external job privilege), some shops abandoned
cron-based jobs and moved everything into Oracle. One benefits of
scheduling Oracle external tasks via dbms_scheduler is that the job
is not "forgotten" if the system is down, as-is the case with crontab
entries. Other shops use more sophisticated job scheduling software
such as Appworx, where complex job dependencies exist.
Shell coding standards - All shell scripts
should follow general coding best practices, including standardized reusable
sub-shells for repetitive tasks (e.g. invoking SQL*Plus), and adhere to
standards for coding style and comments. The best references on best
practices for Oracle shell scripting in the outstanding book "Oracle
Shell Scripting" by Jon Emmons.
See these related notes on Oracle best practices and standards: