Infrastructure at your Service

Yann Neuhaus

Why Perl is my choice for scripting

I have been advising to use Perl for a long time in order to automate Oracle processes and operations. This week however, I tried for once to write a small procedure on a simple Linux shell (ksh and bash). This posting focuses on the shell internals and “nightmares” more than on Oracle related issues.

The goal of this procedure was to “send” a “relocate” to an Oracle Management Server after a failover at the target database. For this purpose, I had to retrieve some information about the Grid Control 11g configuration – OMS host, agent URL, etc.

In order to retrieve the OMS and AGENT URLs, I used the “emctl status agent” command:

[email protected]:/u00/ [AGENT11G] emctl status agent
Oracle Enterprise Manager 11g Release 1 Grid Control
Copyright (c) 1996, 2010 Oracle Corporation.  All rights reserved.
Agent Version     :
OMS Version       :
Protocol Version  :
Agent Home        : /u00/app/oracle/product/agent/agent11g
Agent binaries    : /u00/app/oracle/product/agent/agent11g
Agent Process ID  : 26194
Parent Process ID : 5863
Agent URL         :
Repository URL    :
Started at        : 2011-10-30 02:18:43
Started by user   : oracle
Last Reload       : 2012-01-30 11:52:55
Last successful upload                       : 2012-02-06 12:08:06
Total Megabytes of XML files uploaded so far :  7760.72
Number of XML files pending upload           :        0
Size of XML files pending upload(MB)         :     0.00
Available disk space on upload filesystem    :    60.78%
Last successful heartbeat to OMS             : 2012-02-06 12:18:03
Agent is Running and Ready

For this purpose I wrote a small loop in order to get all the lines in a “shell table”. This offered me the possibility to scan the table afterwards and work on the required variables.

emctl status agent | grep URL | awk '{print $4}' | while read line
let "i = $i + 1"
echo ${var[0]}
echo ${var[1]}

The output is, as expected:

URL of the Agent:
[email protected]:/u00/ [AGENT11G] echo ${var[0]}

URL of the Oracle Management Server (OMS):
[email protected]:/u00/ [AGENT11G] echo ${var[1]}

The used shell was Korn Shel on a Red Hat Linux:

[email protected]:/u00/ [AGENT11G] rpm -qa | grep ksh

[email protected]:/u00/ [AGENT11G] cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.5 (Tikanga)

Unfortunately while running exactly the same code on the following platform (still Korn shell and still Red Hat , but a bit “older”) :

[email protected]:~/ [AGENT11G] cat /etc/redhat-release
Red Hat Enterprise Linux AS release 4 (Nahant Update 8)

[email protected]:~/ [AGENT11G] rpm -qa | grep ksh

The shell table “var” was not available after the execution of the loop (!):

[email protected]:~/ [AGENT11G] echo ${var[0]}

[email protected]:~/ [AGENT11G] echo ${var[1]}

It is also worth to mention that, unfortunately, this piece of code does not work on bash shells.

This confirmed my preference of Perl for these kinds of operations and automations. The several Linux/UNIX shells definitively do behave in quite a different way.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Yann Neuhaus
Yann Neuhaus

Chairman of the Board, Chief Sales Officer (CSO), Region Manager