dbi services: Database Infrastructure Services - Engineering, Implementation, Operation, Modernization

Blog - comments
Julien said,
  Unluckily there is a bug on this feature which causes the reversed eff  
youtube html5 player said,
  Wow, very comprehensive review. I'm thinking about learning HTML5. I'm  
youtube html5 player said,
  I have no words for this great post such a awe-some information i got  
SEO Services said,
  Thanks for the nice blog. It was very useful for me. Keep sharing such  
Jhon said,
  Me personally and my friends genuinely favored the post and i believe  
Blog Yann Neuhaus Why Perl is my choice for scripting

dbi services Blog

Welcome to the dbi services Blog! This blog focuses on database infrastructure and middleware topics. It covers technologies such as Oracle, Microsoft SQL Server, MySQL, Sybase, Linux, or Documentum (etc.). The dbi services blog represents the view of our consultants, not necessarily that of dbi services. Feel free to comment on the postings!

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:

:/u00/ [AGENT11G] emctl status agent

Oracle Enterprise Manager 11g Release 1 Grid Control 11.1.0.1.0
Copyright (c) 1996, 2010 Oracle Corporation.  All rights reserved.
---------------------------------------------------------------
Agent Version     : 11.1.0.1.0
OMS Version       : 11.1.0.1.0
Protocol Version  : 11.1.0.0.0
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         : https://server1.company.com:3872/emd/main/
Repository URL    : https://oemgrid.company.com:4900/em/upload
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.

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

The output is, as expected:

URL of the Agent:
:/u00/ [AGENT11G] echo ${var[0]}
https://server1.company.com:3872/emd/main/

URL of the Oracle Management Server (OMS):
:/u00/ [AGENT11G] echo ${var[1]}
https://doemgrid.company.com:4900/em/upload

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

:/u00/ [AGENT11G] rpm -qa | grep ksh
ksh-20100202-1.el5

:/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") :

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

:~/ [AGENT11G] rpm -qa | grep ksh
pdksh-5.2.14-30.6

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

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

:~/ [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.

About the author

Yann Neuhaus
Yann Neuhaus
Yann Neuhaus is Chief Executive Officer (CEO) and Region Manager at dbi services.

He has more than ten years of experience in database and infrastructure management, engineering, and optimization.

He is specialized in Oracle technologies, cluster computing and high availability solutions (Oracle Real Application Clusters RAC, Oracle Data Guard and Oracle Clusterware). His expertise also includes open source solutions (MySQL, Unix/Linux, etc.).

Yann Neuhaus is „Oracle RAC Certified Expert“, „ MySQL 5.0 DBA certified “, and „Red Hat Certified Engineer“.

Comments

No comments yet. Be the first to submit a comment.
Leave your comment
Guest