{"id":2508,"date":"2012-02-16T12:29:00","date_gmt":"2012-02-16T11:29:00","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/why-perl-is-my-choice-for-scripting\/"},"modified":"2012-02-16T12:29:00","modified_gmt":"2012-02-16T11:29:00","slug":"why-perl-is-my-choice-for-scripting","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/why-perl-is-my-choice-for-scripting\/","title":{"rendered":"Why Perl is my choice for scripting"},"content":{"rendered":"<p>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 &#8220;nightmares&#8221; more than on Oracle related issues.<\/p>\n<p>The goal of this procedure was to &#8220;send&#8221; a &#8220;relocate&#8221; 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 &#8211; OMS host, agent URL, etc.<\/p>\n<p>In order to retrieve the OMS and AGENT URLs, I used the &#8220;emctl status agent&#8221; command:<\/p>\n<pre class=\"brush: actionscript3; gutter: true; first-line: 1\">oracle@server1.company.com:\/u00\/ [AGENT11G] emctl status agent\nOracle Enterprise Manager 11g Release 1 Grid Control 11.1.0.1.0\nCopyright (c) 1996, 2010 Oracle Corporation.\u00a0 All rights reserved.\n---------------------------------------------------------------\nAgent Version\u00a0\u00a0\u00a0\u00a0 : 11.1.0.1.0\nOMS Version\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : 11.1.0.1.0\nProtocol Version\u00a0 : 11.1.0.0.0\nAgent Home\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : \/u00\/app\/oracle\/product\/agent\/agent11g\nAgent binaries\u00a0\u00a0\u00a0 : \/u00\/app\/oracle\/product\/agent\/agent11g\nAgent Process ID\u00a0 : 26194\nParent Process ID : 5863\nAgent URL\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : https:\/\/server1.company.com:3872\/emd\/main\/\nRepository URL\u00a0\u00a0\u00a0 : https:\/\/oemgrid.company.com:4900\/em\/upload\nStarted at\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : 2011-10-30 02:18:43\nStarted by user\u00a0\u00a0 : oracle\nLast Reload\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : 2012-01-30 11:52:55\nLast successful upload\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : 2012-02-06 12:08:06\nTotal Megabytes of XML files uploaded so far :\u00a0 7760.72\nNumber of XML files pending upload\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 :\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0\nSize of XML files pending upload(MB)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 :\u00a0\u00a0\u00a0\u00a0 0.00\nAvailable disk space on upload filesystem\u00a0\u00a0\u00a0 :\u00a0\u00a0\u00a0 60.78%\nLast successful heartbeat to OMS\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : 2012-02-06 12:18:03\n---------------------------------------------------------------\nAgent is Running and Ready<\/pre>\n<p>For this purpose I wrote a small loop in order to get all the lines in a &#8220;shell table&#8221;. This offered me the possibility to scan the table afterwards and work on the required variables.<\/p>\n<pre class=\"brush: actionscript3; gutter: true; first-line: 1\">i=0\nemctl status agent | grep URL | awk '{print $4}' | while read line\ndo\nvar[$i]=$line\nlet \"i = $i + 1\"\ndone\necho ${var[0]}\necho ${var[1]}<\/pre>\n<p>The output is, as expected:<\/p>\n<p>URL of the Agent:<br \/>\n<span style=\"font-family: courier new,courier;\">oracle@server1.company.com:\/u00\/ [AGENT11G] <span style=\"color: #ff0000;\">echo ${var[0]}<\/span><\/span><br \/>\n<span style=\"color: #000000;\"><span style=\"font-family: courier new,courier;\">https:\/\/server1.company.com:3872\/emd\/main\/<\/span><\/span><\/p>\n<p>URL of the Oracle Management Server (OMS):<br \/>\n<span style=\"font-family: courier new,courier;\">oracle@server1.company.com:\/u00\/ [AGENT11G] <span style=\"color: #ff0000;\">echo ${var[1]}<\/span><\/span><br \/>\n<span style=\"font-family: courier new,courier;\">https:\/\/doemgrid.company.com:4900\/em\/upload<\/span><\/p>\n<p>The used shell was Korn Shel on a Red Hat Linux:<\/p>\n<p><span style=\"font-family: courier new,courier;\">oracle@server1.company.com:\/u00\/ [AGENT11G] <span style=\"color: #ff0000;\">rpm -qa | grep ksh<\/span><\/span><br \/>\n<span style=\"font-family: courier new,courier;\">ksh-20100202-1.el5<\/span><\/p>\n<p><span style=\"font-family: courier new,courier;\">oracle@server1.company.com:\/u00\/ [AGENT11G] <span style=\"color: #ff0000;\">cat \/etc\/redhat-release <\/span><\/span><br \/>\n<span style=\"font-family: courier new,courier;\">Red Hat Enterprise Linux Server release 5.5 (Tikanga)<\/span><\/p>\n<p>Unfortunately while running exactly the same code on the following platform (still Korn shell and still Red Hat , but a bit &#8220;older&#8221;) :<\/p>\n<p><span style=\"font-family: courier new,courier;\">oracle@server2.mycompany.com:~\/ [AGENT11G] <span style=\"color: #ff0000;\">cat \/etc\/redhat-release <\/span><\/span><br \/>\n<span style=\"font-family: courier new,courier;\">Red Hat Enterprise Linux AS release 4 (Nahant Update 8)<\/span><\/p>\n<p><span style=\"font-family: courier new,courier;\">oracle@server2.mycompany.com:~\/ [AGENT11G] <span style=\"color: #ff0000;\">rpm -qa | grep ksh<\/span><\/span><br \/>\n<span style=\"font-family: courier new,courier;\">pdksh-5.2.14-30.6<\/span><\/p>\n<p>The shell table &#8220;var&#8221; was not available after the execution of the loop (!):<\/p>\n<p><span style=\"font-family: courier new,courier;\">oracle@server2.mycompany.com:~\/ [AGENT11G] <span style=\"color: #ff0000;\">echo ${var[0]}<\/span><\/span><\/p>\n<p><span style=\"font-family: courier new,courier;\">oracle@server2.mycompany.com:~\/ [AGENT11G] <span style=\"color: #ff0000;\">echo ${var[1]}<\/span><\/span><\/p>\n<p>It is also worth to mention that, unfortunately, this piece of code does not work on bash shells.<\/p>\n<p>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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8220;nightmare&#8221; more than on Oracle related issues.<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[42],"tags":[46,215,47],"type_dbi":[],"class_list":["post-2508","post","type-post","status-publish","format-standard","hentry","category-operating-systems","tag-linux-unix","tag-oracle-enterprise-manager","tag-perl"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Why Perl is my choice for scripting - dbi Blog<\/title>\n<meta name=\"description\" content=\"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).\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/why-perl-is-my-choice-for-scripting\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Why Perl is my choice for scripting\" \/>\n<meta property=\"og:description\" content=\"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).\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/why-perl-is-my-choice-for-scripting\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2012-02-16T11:29:00+00:00\" \/>\n<meta name=\"author\" content=\"Yann Neuhaus\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Yann Neuhaus\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/why-perl-is-my-choice-for-scripting\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/why-perl-is-my-choice-for-scripting\/\"},\"author\":{\"name\":\"Yann Neuhaus\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/5bfc203607127a4915b7950c4a108681\"},\"headline\":\"Why Perl is my choice for scripting\",\"datePublished\":\"2012-02-16T11:29:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/why-perl-is-my-choice-for-scripting\/\"},\"wordCount\":367,\"commentCount\":0,\"keywords\":[\"Linux\/UNIX\",\"Oracle Enterprise Manager\",\"Perl\"],\"articleSection\":[\"Operating systems\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/why-perl-is-my-choice-for-scripting\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/why-perl-is-my-choice-for-scripting\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/why-perl-is-my-choice-for-scripting\/\",\"name\":\"Why Perl is my choice for scripting - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"datePublished\":\"2012-02-16T11:29:00+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/5bfc203607127a4915b7950c4a108681\"},\"description\":\"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).\",\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/why-perl-is-my-choice-for-scripting\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/why-perl-is-my-choice-for-scripting\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/why-perl-is-my-choice-for-scripting\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Why Perl is my choice for scripting\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/5bfc203607127a4915b7950c4a108681\",\"name\":\"Yann Neuhaus\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/d2729b4bbf77b0fe6f6d2b9fb1b2686404c89a16ce2701e860bfd1406212f796?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d2729b4bbf77b0fe6f6d2b9fb1b2686404c89a16ce2701e860bfd1406212f796?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d2729b4bbf77b0fe6f6d2b9fb1b2686404c89a16ce2701e860bfd1406212f796?s=96&d=mm&r=g\",\"caption\":\"Yann Neuhaus\"},\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/yann-neuhaus\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Why Perl is my choice for scripting - dbi Blog","description":"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).","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/why-perl-is-my-choice-for-scripting\/","og_locale":"en_US","og_type":"article","og_title":"Why Perl is my choice for scripting","og_description":"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).","og_url":"https:\/\/www.dbi-services.com\/blog\/why-perl-is-my-choice-for-scripting\/","og_site_name":"dbi Blog","article_published_time":"2012-02-16T11:29:00+00:00","author":"Yann Neuhaus","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Yann Neuhaus","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/why-perl-is-my-choice-for-scripting\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/why-perl-is-my-choice-for-scripting\/"},"author":{"name":"Yann Neuhaus","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/5bfc203607127a4915b7950c4a108681"},"headline":"Why Perl is my choice for scripting","datePublished":"2012-02-16T11:29:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/why-perl-is-my-choice-for-scripting\/"},"wordCount":367,"commentCount":0,"keywords":["Linux\/UNIX","Oracle Enterprise Manager","Perl"],"articleSection":["Operating systems"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/why-perl-is-my-choice-for-scripting\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/why-perl-is-my-choice-for-scripting\/","url":"https:\/\/www.dbi-services.com\/blog\/why-perl-is-my-choice-for-scripting\/","name":"Why Perl is my choice for scripting - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2012-02-16T11:29:00+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/5bfc203607127a4915b7950c4a108681"},"description":"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).","breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/why-perl-is-my-choice-for-scripting\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/why-perl-is-my-choice-for-scripting\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/why-perl-is-my-choice-for-scripting\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Why Perl is my choice for scripting"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/5bfc203607127a4915b7950c4a108681","name":"Yann Neuhaus","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d2729b4bbf77b0fe6f6d2b9fb1b2686404c89a16ce2701e860bfd1406212f796?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d2729b4bbf77b0fe6f6d2b9fb1b2686404c89a16ce2701e860bfd1406212f796?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d2729b4bbf77b0fe6f6d2b9fb1b2686404c89a16ce2701e860bfd1406212f796?s=96&d=mm&r=g","caption":"Yann Neuhaus"},"url":"https:\/\/www.dbi-services.com\/blog\/author\/yann-neuhaus\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/2508","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=2508"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/2508\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=2508"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=2508"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=2508"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=2508"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}