Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles
New Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 
 

Reading an Oracle Shell Script

Oracle Database Tips by Burleson Consulting

August 9, 2015

Check out this valuable book by Jon Emmons on Linux for the Oracle DBA for more tips and tricks.

One of the most confounding issues for the UNIX neophyte is being confronted with a complex UNIX command.  The cryptic nature of UNIX is such that even the most seasoned UNIX professional may have trouble deciphering the purpose of the command.

We will begin by examining a cryptic UNIX command and then see how the command is deciphered by applying a simple set of rules.

Decomposing a UNIX Script  

One of the most foreign concepts for the UNIX neophyte is the ability of the UNIX programmer to string commands together into a powerful one-line script.  Below we see a one-line UNIX script that perform an important Oracle function:

 ps -ef|grep "ora_"|grep -v grep|awk '{ print $2 }'|-exec rm –f {} \;

 At first glance, this powerful UNIX command appears to be a conglomeration of cryptic letters.  However, upon closer examination we see that this UNIX command is actually a series of commands that are joined together with the "pipe" operator "|". 

When viewed this way, our command can be viewed as a connected list of commands:

 ps –ef
|
grep "ora_"
|
grep -v grep
|
awk '{ print $2 }'
|
-exec rm –f {} \;  
 

In this sense, we can examine each command, one at a time, and see how each successive commands refines the output from the prior UNIX command.  Once we see the individual commands that comprise the UNIX script, we are ready to begin building the command from each component.

Deciphering UNIX Command Syntax

In this example, we are examining a UNIX script to kill all Oracle background processes for a database.  There are times when it is necessary to kill all Oracle processes or a selected set of Oracle processes. 

This is a common UNIX script used by an Oracle DBA who wants to kill all Oracle processes when the database is "locked-up" and he cannot enter server manager to gently stop the database.  

The basic format of the UNIX kill command is:  

Kill –9 PID1 PID2 PID3

 (where PIDn is a list of UNIX process ID's)

 To kill all Oracle processes we issue the following command:

 ps -ef|grep "ora_"|grep -v grep|awk '{print $2}'|-exec kill -9 {} \;

 Let's look at how it works:

  1.  The ps –ef UNIX command displays all active processes on the server.  However, we want to limit our command to only those processes that are related to the Oracle database.
     
  2. The "grep "ora_" command removes all but the Oracle background processes:

    >ps -ef|grep "ora_"    
    oracle 13022     1   0   May 07      -  0:18 ora_db02_vald   
    oracle 14796 42726   0 09:00:46  pts/0  0:00 grep ora_   
    oracle 17778     1   0   May 07      -  0:14 ora_smon_devp   
    oracle 18134     1   0   May 07      -  0:37 ora_snp1_vald   
    oracle 19516     1   0   May 07      -  0:24 ora_db04_prod   
    oracle 21114     1   0   May 07      -  0:37 ora_snp0_devp   
    oracle 28436     1   0   May 07      -  0:18 ora_arch_prod
      
     
  3. The "grep –v grep" removes our grep command, so we don't kill our own process.  The grep –v is the opposite of grep, whereas grep find strings, grep –v excludes strings.  Note that the grep line is now missing from our output.  Another alterative to using grep -v is to enclose the target in square brackets (e.g. ps -ef|grep [p]mon)  this has the same functionality as the grep -v grep syntax and removes the grep line:

    >ps -ef|grep "ora_"|grep -v grep    

    oracle 13022     1   0   May 07      -  0:18 ora_db02_vald   
    oracle 17778     1   0   May 07      -  0:14 ora_smon_devp   
    oracle 18134     1   0   May 07      -  0:37 ora_snp1_vald   
    oracle 19516     1   0   May 07      -  0:24 ora_db04_prod   
    oracle 21114     1   0   May 07      -  0:37 ora_snp0_devp   
    oracle 28436     1   0   May 07      -  0:18 ora_arch_prod
        
  4.  We now use the awk command to get the Process ID (PID) for these processes.  The "awk '{print $2}'" command only displays the PID column:

    >ps -ef|grep "ora_"|grep -v grep|awk '{ print $2 }'  

    13022
    17778
    18134
    19516
    21114
    28436
    28956

      
  5. Now we have a list of process ID's for the Oracle background processes.  Finally, we "pipe" the list of PID's to the kill command with "-exec" command.   (Note that HP/UX and AIX also have an "xargs" command for this purpose.

    ps -ef|grep "ora_"|grep -v grep|awk '{ print $2 }'|-exec rm –f {} \;
     
  6. Now that our script is created we can assign it to a UNIX "alias" so we can issue the script in a simple command.  Below, we assign our script to the alias nuke_oracle:

    alias nuke_oracle = "ps -ef|grep "ora_"|grep -v grep|awk '{ print $2 }'|-exec rm –f {} \;"  

    Now, entering the alias nuke_oracle will kill all Oracle background processes.  Of course, we would never risk assigning such a powerful command to an alias in the real-world.  Next, let's create another powerful UNIX script.

Building Commands into Scripts

Now that we know that the "-exec" and "xargs" commands will apply a single UNIX command to a list of inputs, let's look at how we can quickly generate a UNIX script to perform a powerful task.

 
 
 
Get the Complete Details on
Linux System Management for Oracle DBAs  


The landmark book "Linux for the Oracle DBA: The Definitive Reference" provides comprehensive yet specific knowledge on administering Oracle on Linux.   A must-have reference for every DBA running or planning to run Oracle on a Linux platform.

Buy it for 30% off directly from the publisher.
 

 


 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2016

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.


 

��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster