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!
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.
Related Post
- How to connect to an Oracle database using the perl DBI module and DBD::Oracle “as sysdba”? Well, I have read many posts about this, but was unable to find a suitable solution up to now … Google was not my friend ...
- Reading Oracle documentation with an ipad - What Steve Jobs doesn't tell! The christmas period is over and it is now time to enjoy the several gifts brought by Santa Claus. Under my Chrismas tree I discovered an iPad this ye...
- Huge Pages and AMM is (not) possible with 11.2.0.2! ! Read the last comment posted below, this information has been fixed in between - Huge Pages is definitively not possible with AMM ! Huge Pages w...
- Inside Grid Control Lors de mon activité de consultant, et suite à un bug qui n'affiche pas correctement le nombre de CPU (OMS 10.2.0.5, agent 10.2.0.5 et linux x86_64), ...
- Diving into Databases At dbi services, we have a few people passionate about diving. Let me take this opportunity to let you dive into the two databases lakes Oracle and SQ...


