<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Oracle and UNIX Tips</title>
	<atom:link href="http://unbeta.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://unbeta.wordpress.com</link>
	<description>Oracle and UNIX Tips</description>
	<lastBuildDate>Sun, 04 Dec 2011 18:10:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='unbeta.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Oracle and UNIX Tips</title>
		<link>http://unbeta.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://unbeta.wordpress.com/osd.xml" title="Oracle and UNIX Tips" />
	<atom:link rel='hub' href='http://unbeta.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Default Defines in SQL*Plus</title>
		<link>http://unbeta.wordpress.com/2011/11/04/default-defines-in-sqlplus/</link>
		<comments>http://unbeta.wordpress.com/2011/11/04/default-defines-in-sqlplus/#comments</comments>
		<pubDate>Fri, 04 Nov 2011 13:54:49 +0000</pubDate>
		<dc:creator>unbeta</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[define]]></category>
		<category><![CDATA[gloin.sql]]></category>
		<category><![CDATA[login.sql]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[sqlplus]]></category>
		<category><![CDATA[truss]]></category>

		<guid isPermaLink="false">http://unbeta.wordpress.com/?p=64</guid>
		<description><![CDATA[Recently we were executing a script that failed because of a missing tablespace, which had been specified by the &#8216;define&#8217; statement in the script.  The truly odd thing about the failure is that it had been successfully tested in another database on a different box.  After investigating and a little research we determined the problem. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=unbeta.wordpress.com&amp;blog=2063191&amp;post=64&amp;subd=unbeta&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently we were executing a script that failed because of a missing tablespace, which had been specified by the &#8216;define&#8217; statement in the script.  The truly odd thing about the failure is that it had been successfully tested in another database on a different box.  After investigating and a little research we determined the problem.</p>
<p>The initial suspicion was that we had a &#8216;glogin.sql&#8217; file that contained the extra &#8216;defines&#8217; since they showed up by default when logging into SQL*Plus.  None of the &#8216;glogin.sql&#8217; scripts on this box had the &#8216;defines&#8217;, so we ran a &#8216;truss&#8217; on a SQL*Plus session that allowed us to determine the source of the settings.  The truss utility is excellent for finding out what files are opened by a process; the short form of our output looked a little like this:</p>
<pre style="padding-left:30px;">access("./login.sql", 0)                        = 0
access("././login.sql", 0)                      = 0
access("./login.sql", 0)                        = 0
access("././login.sql", 0)                      = 0
__libc_sbrk(0x0000000000030020)                 = 0x000000011025C480
access("././login.sql", 0)                      = 0
statfs("././login.sql", 0x0FFFFFFFFFFFD4B0)     = 0
mntctl(2, 512, "")                              = 0
mntctl(2, 6376, "")                             = 24
kopen("/etc/vfs", O_RDONLY)                     = 9
kioctl(9, 22528, 0x0000000000000000, 0x0000000000000000) Err#25 ENOTTY
kioctl(9, 22528, 0x0000000000000000, 0x0000000000000000) Err#25 ENOTTY
kread(9, " #   @ ( # ) v f s     @".., 4096)    = 1772
close(9)                                        = 0
kopen("././login.sql", O_RDONLY|O_LARGEFILE)    = 9</pre>
<p>So, it looked like we were getting these values from a &#8216;login.sql&#8217; instead of a &#8216;glogin.sql&#8217; file.  Since it looked like default directories  were included in the search order, we looked in the home directory of the non-oracle UNIX account, and we found the culprit.  We renamed the &#8216;login.sql&#8217; file and the &#8216;defines&#8217; disappeared.</p>
<p>During the research, we found a lot of references to the SQLPATH variable, but ours was empty.  The driver for our problem turned out to be the ORACLE_PATH variable, which contains our home directory, the current &#8216;.&#8217; directory, and several others that had been added over the years.  According to Metalink Note 1012298.6, this setting controls the search path for &#8216;glogin.sql&#8217; and &#8216;login.sql&#8217;, which explains why our &#8216;login.sql&#8217; file, residing in our $HOME directory, was causing our default &#8216;defines&#8217;.  The most disturbing find of this whole exercise was that, from 10g on, the &#8216;login.sql&#8217; script is executed <em>every time a &#8216;connect&#8217; occurs</em> in a script.  So, this means that even if  &#8216;defines&#8217; are created by a primary script, the values can be accidentally overwritten following a connect, if those values are defined in a &#8216;login.sql&#8217; file, forcing all downstream scripts use the default values.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/unbeta.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/unbeta.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/unbeta.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/unbeta.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/unbeta.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/unbeta.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/unbeta.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/unbeta.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/unbeta.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/unbeta.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/unbeta.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/unbeta.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/unbeta.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/unbeta.wordpress.com/64/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=unbeta.wordpress.com&amp;blog=2063191&amp;post=64&amp;subd=unbeta&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://unbeta.wordpress.com/2011/11/04/default-defines-in-sqlplus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/333e31e2c8f8fa7759ae6dc8c97fc733?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">unbeta</media:title>
		</media:content>
	</item>
		<item>
		<title>Preventing Duplicate Runs In A UNIX Shell Script</title>
		<link>http://unbeta.wordpress.com/2011/10/11/preventing-duplicate-runs-in-a-unix-shell-script/</link>
		<comments>http://unbeta.wordpress.com/2011/10/11/preventing-duplicate-runs-in-a-unix-shell-script/#comments</comments>
		<pubDate>Tue, 11 Oct 2011 18:01:11 +0000</pubDate>
		<dc:creator>unbeta</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[daemon]]></category>
		<category><![CDATA[duplicate run]]></category>
		<category><![CDATA[korn shell]]></category>
		<category><![CDATA[prevent]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://unbeta.wordpress.com/?p=62</guid>
		<description><![CDATA[There are several ways to prevent a UNIX shell script from running multiple times simultaneously.  This post will describe a couple of ways to accomplish this.  Naturally, the first inclination generally  is to simply use &#8216;ps -ef&#8217; to look for the presence of your script and exit if a currently executing copy is found.  This [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=unbeta.wordpress.com&amp;blog=2063191&amp;post=62&amp;subd=unbeta&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There are several ways to prevent a UNIX shell script from running multiple times simultaneously.  This post will describe a couple of ways to accomplish this.  Naturally, the first inclination generally  is to simply use &#8216;ps -ef&#8217; to look for the presence of your script and exit if a currently executing copy is found.  This has several drawbacks, one of which is the tendency towards confusion when another  process is editing, tailing, or otherwise interacting with the script, yet it&#8217;s not really being <em>executed</em>, which is what we&#8217;re trying to prevent.  The two methods described here are <strong><em>daemons</em></strong> and <strong><em>PID files</em></strong>.</p>
<p>If there is a script that needs to be executed every minute, such as a monitoring tool, it can be scheduled in cron and the functionality to prevent duplicate runs can be embedded, which we&#8217;ll cover later.  Another alternative is to execute the script as a UNIX daemon.  This sounds a lot more complicated that it really is, so let&#8217;s dig into it.  First, the script will need to execute in a continuous loop, with some sort of sleep in between runs to prevent it from spinning on a CPU.  This is accomplished by updating the logic inside the script to something like this:</p>
<pre style="padding-left:30px;">while true
do
  call_your_main_function

  sleep 30
done</pre>
<p>Now, add it to the &#8216;/etc/inittab&#8217; and the script will run continuously, without running over top of itself.  In Linux, edit the &#8216;/etc/inittab&#8217; file and add a new entry:</p>
<pre style="padding-left:30px;">newscr:35:respawn:/sbin/runuser -s /bin/ksh oracle -c /path_to_your_script/your_script_name</pre>
<p>Where:</p>
<pre style="padding-left:30px;">newscr    Abbreviated name for your script
35        Linux run levels that should be executing this script (3 &amp; 5)
respawn   Automatically respawn the script if it dies
name      The name of the script to execute, with a fully qualified path.
          Also include something similar to the 'runser' command
          if the script is to be executed by non-root UNIX acccount.</pre>
<p>Issue the &#8216;init q&#8217; command to reload the &#8216;/etc/inittab&#8217; and the script should start executing as a daemon.  AIX requires the use of the &#8216;mkitab&#8217; command to create a new entry, but otherwise it works in a similar fashion.  Another advantage of this technique over cron is that the &#8216;sleep&#8217; setting can be adjusted, thereby running a script on intervals less than one minute.  This would depend on the length of time required to execute the function inside the loop.</p>
<p>Another method for preventing duplicate runs is to use the very common Linux/UNIX concept of a PID file.  This is simply a file, in a known location, that contains the process ID of the executing script.  This file can be used as a lookup device to make sure the script matches the PID and exiting the script if needed.</p>
<p>A basic implementation of this requires very little coding.  At the top of the script, capture the command line that was used when the script was called:</p>
<pre style="padding-left:30px;"># Save off the current script name with all command-line parameters
if [[ "$*" != "" ]]
then
  CURRENT_SCRIPT="$(print "$_" | awk -F \/ '{print $NF}') $*"
else
  CURRENT_SCRIPT="$(print "$_" | awk -F \/ '{print $NF}')"
fi</pre>
<p>Then, name the &#8216;PID&#8217; file somewhere in the top of the script:</p>
<pre style="padding-left:30px;">PIDFILE="/var/tmp/myscript.pid"</pre>
<p>Add a function that can check the &#8216;PID&#8217; file against the system:</p>
<pre style="padding-left:30px;">function already_running {
  # No PID file means it's not running
  if [[ ! -f $PIDFILE ]]
  then
    return 1
  fi

  if [[ $(ps -p $(cat $PIDFILE) -o args | grep -c "${CURRENT_SCRIPT}") -ne 0 ]]
  then
    return 0
  else
    return 1
  fi
}</pre>
<p>Before any action occurs in the script, check and exit if it&#8217;s already being executed:</p>
<pre style="padding-left:30px;"># Prevent multiple copies from running
if already_running
then
  # Print the results in an interactive shell
  if [[ -t 1 ]]
  then
    echo "Another copy is already running, exiting."
  fi

  exit 1
fi</pre>
<p>Now,  save off the current PID if it wasn&#8217;t already running:</p>
<pre style="padding-left:30px;"># Save off the current PID
echo "$$" &gt; ${PIDFILE}</pre>
<p>Hopefully, one of these two techniques will allow your script to implement duplicate-run prevention.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/unbeta.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/unbeta.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/unbeta.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/unbeta.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/unbeta.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/unbeta.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/unbeta.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/unbeta.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/unbeta.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/unbeta.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/unbeta.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/unbeta.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/unbeta.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/unbeta.wordpress.com/62/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=unbeta.wordpress.com&amp;blog=2063191&amp;post=62&amp;subd=unbeta&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://unbeta.wordpress.com/2011/10/11/preventing-duplicate-runs-in-a-unix-shell-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/333e31e2c8f8fa7759ae6dc8c97fc733?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">unbeta</media:title>
		</media:content>
	</item>
		<item>
		<title>LDAP Cutover and the &#8216;/etc/passwd&#8217; File</title>
		<link>http://unbeta.wordpress.com/2011/09/27/ldap-cutover-and-the-etcpasswd-file/</link>
		<comments>http://unbeta.wordpress.com/2011/09/27/ldap-cutover-and-the-etcpasswd-file/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 20:24:20 +0000</pubDate>
		<dc:creator>unbeta</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://unbeta.wordpress.com/?p=59</guid>
		<description><![CDATA[We are currently testing an LDAP implementation at work and we ran into an interesting scenario.  It turns out that we had a script (written in C), that parsed the &#8216;/etc/passwd&#8217; file in AIX to ensure that a particular UID belonged to the appropriate user.  Once we cut over to LDAP, this no longer worked since [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=unbeta.wordpress.com&amp;blog=2063191&amp;post=59&amp;subd=unbeta&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We are currently testing an LDAP implementation at work and we ran into an interesting scenario.  It turns out that we had a script (written in C), that parsed the &#8216;/etc/passwd&#8217; file in AIX to ensure that a particular UID belonged to the appropriate user.  Once we cut over to LDAP, this no longer worked since the entries are not kept in &#8216;/etc/passwd&#8217; for non-system accounts.  To compensate for this change with the least amount of change to the C source, I wrote a Korn Shell script that created the same output as &#8216;cat /etc/passwd&#8217; using the &#8216;lsuser&#8217; command in AIX.  This wouldn&#8217;t work in Linux, but we only have a need in AIX at this point.  In other scripts, we have been able to convert to the &#8216;finger -m&#8217; command because we are only interested in users that are currently logged into the box.</p>
<p>To obtain the information from the &#8216;lsuer&#8217; command, we first obtain a list of all accounts on the box like this:</p>
<pre>lsuser | awk '{print $1}'</pre>
<p>We then parse through the results of this and query each account individually:</p>
<pre>lsuser | awk '{print $1}' | while read NAME; do lsuser -f $NAME; done</pre>
<p>Taking this output, it&#8217;s fairly straightforward to write a script that creates the same output as &#8216;cat /etc/passwd&#8217;.  The 2nd field is hardcoded in the output as an empty string since the O/S manipulates this value and it&#8217;s not important for this exercise.</p>
<p>Once a script had been written that would produce the same output, a change was made to the C source that used a &#8216;popen/pclose&#8217; instead of an &#8216;fopen/fclose&#8217;.  It took some experimenting but it finally worked, after I <em>remembered</em> that the &#8216;rm&#8217; command in UNIX requires an &#8216;-f&#8217; switch if a setuid bit is set on the source binary; otherwise the &#8216;are you sure?&#8217; prompt requires user input during the execution of the &#8216;popen&#8217;.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/unbeta.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/unbeta.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/unbeta.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/unbeta.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/unbeta.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/unbeta.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/unbeta.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/unbeta.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/unbeta.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/unbeta.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/unbeta.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/unbeta.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/unbeta.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/unbeta.wordpress.com/59/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=unbeta.wordpress.com&amp;blog=2063191&amp;post=59&amp;subd=unbeta&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://unbeta.wordpress.com/2011/09/27/ldap-cutover-and-the-etcpasswd-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/333e31e2c8f8fa7759ae6dc8c97fc733?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">unbeta</media:title>
		</media:content>
	</item>
		<item>
		<title>Oracle OID to TNS</title>
		<link>http://unbeta.wordpress.com/2011/09/19/oracle-oid-to-tns/</link>
		<comments>http://unbeta.wordpress.com/2011/09/19/oracle-oid-to-tns/#comments</comments>
		<pubDate>Mon, 19 Sep 2011 14:46:04 +0000</pubDate>
		<dc:creator>unbeta</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[oid ldap tns awk]]></category>

		<guid isPermaLink="false">http://unbeta.wordpress.com/?p=54</guid>
		<description><![CDATA[If you ever need to dump the contents of an Oracle OID (LDAP) server to a tnsnames.ora file, there&#8217;s an easy method using an awk script I wrote.  The interesting thing about this script is that the output will be neatly formatted automatically. The awk script consists of this: **** Cut here **** BEGIN {PAD="  [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=unbeta.wordpress.com&amp;blog=2063191&amp;post=54&amp;subd=unbeta&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you ever need to dump the contents of an Oracle OID (LDAP) server to a tnsnames.ora file, there&#8217;s an easy method using an awk script I wrote.  The interesting thing about this script is that the output will be neatly formatted automatically.</p>
<p>The awk script consists of this:</p>
<p>**** Cut here ****</p>
<pre>BEGIN {PAD="  ";CNT=0;FS="="}
{OUT=""; PC=1;CNT+=1}
{
  if (CNT == 1)
  {
    O=$2
    sub(",cn","",O)
    print O " = "
  }
  else if (CNT == 2)
  {
    sub("^orclnetdescstring=","",$0)
    {for (i=1;i&lt;=length;i++)
      {
        CHR=substr($0,i,1)

        if (CHR == "(")
        {
          PC+=1

          WRK=OUT
          sub(/ */,"",WRK)
          if (WRK != "")
            printf OUT "\n"

          OUT=""
          for (p=1;p&lt;PC;p++)
            OUT=PAD OUT

          OUT=OUT CHR
        }
        else if (CHR == ")")
        {
          OUT=OUT CHR
          printf OUT "\n"
          PC-=1
          OUT=""

          for (p=1;p&lt;PC;p++)
            OUT=OUT PAD

        }
        else
          OUT=OUT CHR
      }
    }
  }
  else if (CNT == 3)
    CNT=0
}</pre>
<p>**** Cut here ****</p>
<p>To use this awk script, paste everything  in between the &#8216;**** Cut here ****&#8217; lines into a file and name it whatever you like, for example &#8216;oid2tns.awk&#8217;.  Once we have the script, we need to query the OID server and pass along the output.  This will require a server that has OID installed; in our case we use the OID built into OAS.  If you have your infrastructure and MT built on the same box, make sure you set the environment for infrastructure.</p>
<p>Here&#8217;s the syntax to combine the OID query and the awk script:</p>
<pre style="padding-left:30px;">$ORACLE_HOME/bin/ldapsearch -h [SubYourOID] -b '' -s sub '(objectclass=orclNetService)' orclNetDescString | awk -f oid2tns.awk</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/unbeta.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/unbeta.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/unbeta.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/unbeta.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/unbeta.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/unbeta.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/unbeta.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/unbeta.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/unbeta.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/unbeta.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/unbeta.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/unbeta.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/unbeta.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/unbeta.wordpress.com/54/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=unbeta.wordpress.com&amp;blog=2063191&amp;post=54&amp;subd=unbeta&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://unbeta.wordpress.com/2011/09/19/oracle-oid-to-tns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/333e31e2c8f8fa7759ae6dc8c97fc733?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">unbeta</media:title>
		</media:content>
	</item>
		<item>
		<title>Data Dictionary Query</title>
		<link>http://unbeta.wordpress.com/2011/09/06/data-dictionary-query/</link>
		<comments>http://unbeta.wordpress.com/2011/09/06/data-dictionary-query/#comments</comments>
		<pubDate>Tue, 06 Sep 2011 18:31:46 +0000</pubDate>
		<dc:creator>unbeta</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cost-based]]></category>
		<category><![CDATA[data dictionary]]></category>
		<category><![CDATA[optimizer]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[rule-based]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[tune]]></category>

		<guid isPermaLink="false">http://unbeta.wordpress.com/?p=48</guid>
		<description><![CDATA[We have been working through all of the SQL with high buffer-gets in our Banner databases and we came across a data-dictionary query that is performing 300 million per day: SELECT a.column_name FROM all_tab_columns a, all_ind_columns b WHERE a.table_name = b.table_name AND a.column_name = b.column_name AND a.owner = b.index_owner AND b.table_name = :1 AND b.index_owner [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=unbeta.wordpress.com&amp;blog=2063191&amp;post=48&amp;subd=unbeta&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We have been working through all of the SQL with high buffer-gets in our Banner databases and we came across a data-dictionary query that is performing 300 million per day:</p>
<pre>SELECT a.column_name
 FROM all_tab_columns a, all_ind_columns b
 WHERE a.table_name = b.table_name
 AND a.column_name = b.column_name
 AND a.owner = b.index_owner
 AND b.table_name = :1
 AND b.index_owner = :1
 AND b.index_name =
 (SELECT constraint_name
 FROM all_constraints
 WHERE table_name = :1
 AND owner = :1
 AND constraint_type = :1
 AND ROWNUM = 1)</pre>
<p>So, we figured out that this query was coming from a forms library file (*.pll) and it&#8217;s used on a few forms that support user-defined columns.  This is similar to flex-fields in ERP.  Unfortunately, this query uses rule-based optimization so it can be a challenge to tune.  After some research, it was determined that this query could be rewritten to force cost-based optimization with a slight tweak:</p>
<pre>SELECT a.column_name
 FROM <strong><span style="color:#ff0000;">all_tab_cols</span></strong> a, all_ind_columns b
 WHERE a.table_name = b.table_name
 AND a.column_name = b.column_name
 AND a.owner = b.index_owner
 AND b.table_name = :1
 AND b.index_owner = :1
 AND b.index_name =
 (SELECT constraint_name
 FROM all_constraints
 WHERE table_name = :1
 AND owner = :1
 AND constraint_type = :1
 AND ROWNUM = 1)</pre>
<p>This query now performs 10,000 buffer-gets per run!  At least we can tune it knowing the cost.  Next, we added some hints:</p>
<pre>SELECT <strong><span style="color:#ff0000;">/*+ NO_CPU_COSTING */</span></strong> a.column_name
 FROM all_tab_cols a,
 all_ind_columns b
 WHERE a.table_name = b.table_name
 AND a.column_name = b.column_name
 AND a.owner = b.index_owner
 AND b.table_name = :1
 AND b.index_owner = :1
 AND b.index_name = <strong><span style="color:#ff0000;">ANY</span></strong> (SELECT constraint_name
 FROM all_constraints
 WHERE table_name = :1
 AND owner = :1
 AND constraint_type = 'P'
 AND ROWNUM = 1)</pre>
<p>We finish this off by adding some sys stats:</p>
<pre>EXEC DBMS_STATS.GATHER_DICTIONARY_STATS;</pre>
<p>At last!  This new, improved query creates 8 buffer-gets per execution.  A pretty good improvement for such a tiny fix.  We updated the &#8216;.pll&#8217;, recompiled all the forms, and we&#8217;re ready to move on to the next challenge.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/unbeta.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/unbeta.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/unbeta.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/unbeta.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/unbeta.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/unbeta.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/unbeta.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/unbeta.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/unbeta.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/unbeta.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/unbeta.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/unbeta.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/unbeta.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/unbeta.wordpress.com/48/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=unbeta.wordpress.com&amp;blog=2063191&amp;post=48&amp;subd=unbeta&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://unbeta.wordpress.com/2011/09/06/data-dictionary-query/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/333e31e2c8f8fa7759ae6dc8c97fc733?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">unbeta</media:title>
		</media:content>
	</item>
		<item>
		<title>Quest SQL Optimizer</title>
		<link>http://unbeta.wordpress.com/2011/09/01/quest-sql-optimizer/</link>
		<comments>http://unbeta.wordpress.com/2011/09/01/quest-sql-optimizer/#comments</comments>
		<pubDate>Thu, 01 Sep 2011 17:43:50 +0000</pubDate>
		<dc:creator>unbeta</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[killed]]></category>
		<category><![CDATA[Quest]]></category>
		<category><![CDATA[SQL Optimizer]]></category>

		<guid isPermaLink="false">http://unbeta.wordpress.com/?p=39</guid>
		<description><![CDATA[We recently purchased licenses for the Quest tool SQL Optimizer.  This is a highly recommended piece of software if you can spare the money, since it easily allows different query strategies to iteratively  be tested on a problematic piece of SQL.  Everything was going just fine until I increased the optimizer and index  intelligence levels [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=unbeta.wordpress.com&amp;blog=2063191&amp;post=39&amp;subd=unbeta&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We recently purchased licenses for the Quest tool SQL Optimizer.  This is a highly recommended piece of software if you can spare the money, since it easily allows different query strategies to iteratively  be tested on a problematic piece of SQL.  Everything was going just fine until I increased the optimizer and index  intelligence levels both to the max!  After the tool automatically  tested about different 40 different scenarios, it appeared to lose its mind slightly.  After trying to kill it gracefully, with no luck, I killed it using the Windows Task Manager.  I quickly forgot about it since I was leaving for the day.</p>
<p>The next day I started up SQL Optimizer and it looked different.  I could no longer enter in a query.  The screen looked almost blank.  So, I uninstalled and reinstalled with no luck.  I figured it automatically saved session information, and it turned out I was correct.  So, to solve this problem I did this:</p>
<ul>
<li>Uninstalled SQL Optimizer.</li>
<li>Deleted the complete directory structure from this point down: &#8216;c:\Documents and Settings\[MyLogin]\Application Data\Quest Software\Quest SQL Optimizer for Oracle&#8217;.</li>
<li>Reinstalled SQL Optimizer.</li>
</ul>
<p>Hopefully this will save you some time if you ever encounter this same type of situation.</p>
<p>ETA:  I&#8217;ve encountered this same scenario several more times, but I have figured out that the product doesn&#8217;t need to be uninstalled.  Just delete the directory and SQL Optimizer will recreate it once it relaunches.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/unbeta.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/unbeta.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/unbeta.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/unbeta.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/unbeta.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/unbeta.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/unbeta.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/unbeta.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/unbeta.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/unbeta.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/unbeta.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/unbeta.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/unbeta.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/unbeta.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=unbeta.wordpress.com&amp;blog=2063191&amp;post=39&amp;subd=unbeta&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://unbeta.wordpress.com/2011/09/01/quest-sql-optimizer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/333e31e2c8f8fa7759ae6dc8c97fc733?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">unbeta</media:title>
		</media:content>
	</item>
		<item>
		<title>Utilizing Large Memory Pages for Oracle on AIX</title>
		<link>http://unbeta.wordpress.com/2010/08/30/utilizing-large-memory-pages-for-oracle-on-aix/</link>
		<comments>http://unbeta.wordpress.com/2010/08/30/utilizing-large-memory-pages-for-oracle-on-aix/#comments</comments>
		<pubDate>Mon, 30 Aug 2010 19:57:15 +0000</pubDate>
		<dc:creator>unbeta</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://unbeta.wordpress.com/?p=23</guid>
		<description><![CDATA[Recently, we were upgrading to ERP R12 and decided to utilize large memory pages in AIX since we had 196gb available during the upgrade and large memory pages would gain significant throughput.  There were a couple of lessons learned along the way, though, even if we had already successfully implemented this strategy in several AIX [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=unbeta.wordpress.com&amp;blog=2063191&amp;post=23&amp;subd=unbeta&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><!--[if gte mso 9]&gt;--></p>
<p>Recently, we were upgrading to ERP R12 and decided to utilize large memory pages in AIX since we had 196gb available during the upgrade and large memory pages would gain significant throughput.  There were a couple of lessons learned along the way, though, even if we had already successfully implemented this strategy in several AIX 10gR1 databases.</p>
<p>For the record, Metalink has a pretty good article (Note ID 372157.1) on setting up your system for large memory pages so there&#8217;s no need to regurgitate the entire thing, but here are the steps in a nutshell.  Be forewarned that Oracle Support will probably fight you every step of the way since this process negates the need for AMM, but 23% performance gains on our batch processes speaks for itself.</p>
<ol>
<li>Configure      the AIX large page pool by calculating the number of large pages required      for the SGA:
<ul>
<li>num_of_large_pages       = INT((total_SGA_size-1)/16MB)+1</li>
<li>As       root:
<ul>
<li><strong>vmo -p -o lgpg_regions=num_of_large_pages -o lgpg_size=16777216</strong></li>
<li><strong> </strong><strong>vmo -o lru_file_repage=0</strong></li>
<li><strong> </strong></li>
</ul>
</li>
<li>Bear       in mind that the PGA is not part of the SGA and will not utilize the       large memory pages.  If not specified       in the init file, the PGA defaults to 20% of the size of the SGA.</li>
<li>We       always configure more large memory pages than we need.  If the box needs excessive pages for       small memory segments it will effectively ‘eat’ pages to provide the       minimum small segments.  This can       be a cpu-intensive exercise so it’s best to avoid it altogether.</li>
</ul>
</li>
<li>Enable      the Oracle UNIX account to access large memory pages.
<ul>
<li>As       root, check the current settings for the user account:
<ul>
<li><strong>lsuser -a capabilities oracle</strong></li>
</ul>
</li>
<li>Add the ‘CAP_BYPASS_RAC_VMM’ and ‘CAP_PROPAGATE’ if needed:
<ul>
<li><strong>chuser capabilities=CAP_BYPASS_RAC_VMM,CAP_PROPAGATE oracle</strong></li>
</ul>
</li>
<li>We encountered a bug in Oracle 10.0.4.2 that prevented the database from using large memory pages.  There are two notes (372157.1 &amp;<strong> </strong>ID 728444.1) that document the workarounds.  As oracle, edit the XCOFF file header in the oracle binary to enable it to use large page data and set an environmental variable:
<ul>
<li><strong>export ORACLE_SGA_PGSZ=16m</strong></li>
<li><strong> </strong><strong>cd $ORACLE_HOME/bin/oracle</strong></li>
<li><strong> </strong><strong>cp –p oracle oracle.orig</strong></li>
<li><strong> </strong><strong>ldedit -b lpdata oracle</strong></li>
<li><strong> </strong></li>
</ul>
</li>
</ul>
</li>
<li>Configure      the SGA to best utilize large memory pages.
<ul>
<li>Set       ‘pre_page_sga=false’ so that the instance doesn’t timeout trying to pre-page       all of those large memory pages.</li>
<li>Set       ‘lock_sga=true’ so that you get a contiguous piece of memory that can’t       be taken by another process on the box.</li>
<li>Set       ‘sga_target=0’ so that automatic memory management is turned off.  There is no need to dynamically resize       memory settings when a large SGA is in use.  By the time the instance figures out       what to resize, it’s too late.</li>
<li>Set       ‘db_block_hash_latches=32768’ to take advantage of the extra memory       pages.</li>
</ul>
</li>
<li>Verify      the use of large memory pages:
<ul>
<li>Get       the PID of the ‘pmon’ process:
<ul>
<li><strong>PID=$(ps –ef | grep pmon | grep ${ORACLE_SID})</strong></li>
</ul>
</li>
<li>Look       at the memory usage of the PID:
<ul>
<li><strong>svmon –P ${PID}</strong></li>
</ul>
</li>
</ul>
</li>
</ol>
<pre style="padding-left:150px;">-------------------------------------------------------------------------------</pre>
<pre style="padding-left:150px;">Pid Command          Inuse      Pin     Pgsp  Virtual 64-bit Mthrd  16MB</pre>
<pre style="padding-left:150px;">7603124 oracle        13461204 13381632        0 13409786      Y     N     Y</pre>
<pre style="padding-left:150px;">PageSize                Inuse        Pin       Pgsp    Virtual</pre>
<pre style="padding-left:150px;">s    4 KB               56900          0          0       5482</pre>
<pre style="padding-left:150px;">m   64 KB                1929        512          0       1929</pre>
<pre style="padding-left:150px;">L   16 MB                3265       3265          0       3265</pre>
<pre style="padding-left:150px;">Vsid      Esid Type Description              PSize  Inuse   Pin Pgsp Virtual</pre>
<pre style="padding-left:150px;">1ef68ef  7000001a work default shmat/mmap           L     16    16    0      16</pre>
<pre style="padding-left:150px;">1ab3aab  70000012 work default shmat/mmap           L     16    16    0      16</pre>
<pre style="padding-left:150px;">1c14ec1  70000059 work default shmat/mmap           L     16    16    0      16</pre>
<pre style="padding-left:150px;">18f308f  70000080 work default shmat/mmap           L     16    16    0      16</pre>
<ul>
<li>
<ul>
<li>
<ul>
<li><strong>svmon -G</strong></li>
</ul>
</li>
</ul>
</li>
</ul>
<pre style="padding-left:150px;">size       inuse        free         pin     virtual   mmode</pre>
<p style="padding-left:150px;"><strong> </strong></p>
<pre style="padding-left:150px;">memory     20971520    19946466     1025054    15275762    19163953     Ded</pre>
<pre style="padding-left:150px;">pg space   25165824       40491</pre>
<pre style="padding-left:150px;">work        pers        clnt       other</pre>
<pre style="padding-left:150px;">pin        14627122           0           0      644544</pre>
<pre style="padding-left:150px;">in use     19163953           0      778417</pre>
<pre style="padding-left:150px;">PageSize   PoolSize       inuse        pgsp         pin     virtual</pre>
<pre style="padding-left:150px;">s    4 KB         -     5085122       40491      831554     4306705</pre>
<pre style="padding-left:150px;">m   64 KB         -       92738           0       66667       92738</pre>
<pre style="padding-left:150px;">L   16 MB      3266        3265           0        3266        3265</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/unbeta.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/unbeta.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/unbeta.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/unbeta.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/unbeta.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/unbeta.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/unbeta.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/unbeta.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/unbeta.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/unbeta.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/unbeta.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/unbeta.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/unbeta.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/unbeta.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=unbeta.wordpress.com&amp;blog=2063191&amp;post=23&amp;subd=unbeta&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://unbeta.wordpress.com/2010/08/30/utilizing-large-memory-pages-for-oracle-on-aix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/333e31e2c8f8fa7759ae6dc8c97fc733?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">unbeta</media:title>
		</media:content>
	</item>
		<item>
		<title>Korn Shell Functions</title>
		<link>http://unbeta.wordpress.com/2008/07/20/korn-shell-functions/</link>
		<comments>http://unbeta.wordpress.com/2008/07/20/korn-shell-functions/#comments</comments>
		<pubDate>Sun, 20 Jul 2008 16:51:54 +0000</pubDate>
		<dc:creator>unbeta</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://unbeta.wordpress.com/?p=10</guid>
		<description><![CDATA[Korn Shell functions are an easy way to break larger Korn Shell scripts into more manageable chunks.  You have the option of using the function to return a true/false value as well as normal number or string output.  The basic format of a function in the Korn Shell is like this: function test_function { typeset [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=unbeta.wordpress.com&amp;blog=2063191&amp;post=10&amp;subd=unbeta&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal"><!--[if gte mso 10]&gt;-->Korn Shell functions are an easy way to break larger Korn Shell scripts into more manageable chunks.  You have the option of using the function to return a true/false value as well as normal number or string output.  The basic format of a function in the Korn Shell is like this:</p>
<p class="MsoNormal">function test_function {</p>
<p class="MsoNormal" style="padding-left:30px;">typeset local_variables</p>
<p class="MsoNormal" style="padding-left:30px;">body_of_function</p>
<p class="MsoNormal">}</p>
<p class="MsoNormal">It’s always a good idea to declare your local variables in a function using the ‘typeset’ command so they don’t inherit values from calling functions or scripts.  The command-line parameters become localized in a function so ‘$1’ isn’t the same as the ‘$1’ that was passed to the originating script.  If you want to pass parameters to a function, call it with the values like this: “test_function parameter1 parameter2”.  If you want to pass on the original values passed to the script on the command line, pass them to the function like this: “test_function $1” or to pass all of the parameters, like this: “test_function $@”.  Please note use of the ‘shift’ statement will clear out the command line switches so this will not work if the command line switches have been parsed and removed from the environment.</p>
<p class="MsoNormal">The returning of true/false values from functions is counter-intuitive when you are more familiar with other languages.  In Korn Shell, a value of zero passed back from a function equals ‘true’ and a value of non-zero equals &#8216;false&#8217;.  So, here’s how this plays out:</p>
<p class="MsoNormal">function test_name {</p>
<p class="MsoNormal" style="padding-left:30px;">typeset FIRST=”$1”</p>
<p class="MsoNormal" style="padding-left:30px;">typeset LAST=”$2”</p>
<p class="MsoNormal" style="padding-left:30px;">if [[ “$FIRST” = “$LAST” ]]</p>
<p class="MsoNormal" style="padding-left:30px;">then</p>
<p class="MsoNormal" style="padding-left:60px;">return 0</p>
<p class="MsoNormal" style="padding-left:30px;">else</p>
<p class="MsoNormal" style="padding-left:60px;">return 1</p>
<p class="MsoNormal" style="padding-left:30px;">fi</p>
<p class="MsoNormal">}</p>
<p class="MsoNormal">read FIRST?”Enter first name: “</p>
<p class="MsoNormal">read LAST?”Enter last name: “</p>
<p class="MsoNormal">if test_name “$FIRST” “$LAST”</p>
<p class="MsoNormal">then</p>
<p class="MsoNormal" style="padding-left:30px;">print “First name equals last”</p>
<p class="MsoNormal">else</p>
<p class="MsoNormal" style="padding-left:30px;">print “First name does not equal last”</p>
<p class="MsoNormal">fi</p>
<p class="MsoNormal">Now, when this script is executed, it asks for a first and last name and indicates if they are the same.  This is not very useful as a script but it illustrates the true/false return quite nicely.  It should be noted that functions return the value of the last statement executed.  The ‘return’ statement exits the function as well as providing the appropriate feedback.  Also, note that double-quotes were used to supply the parameters to the function.  This ensures that the entire variable is passed as “$1” or “$2” instead of interpreting spaces as a separator in the call.</p>
<p class="MsoNormal">Here’s an example of a function returning a string value instead of Boolean:</p>
<p class="MsoNormal">function full_name {</p>
<p class="MsoNormal" style="padding-left:30px;">typeset FIRST=”$1”</p>
<p class="MsoNormal" style="padding-left:30px;">typeset LAST=”$2”</p>
<p class="MsoNormal" style="padding-left:30px;">print “$FIRST $LAST”</p>
<p class="MsoNormal">}</p>
<p class="MsoNormal">read FIRST?”Enter first name: “</p>
<p class="MsoNormal">read LAST?”Enter last name: “</p>
<p class="MsoNormal">print “Full Name=$(full_name“$FIRST” “$LAST”)”</p>
<p class="MsoNormal">This brings up another interesting point.  You can call a function using the old-style of the grave symbols:</p>
<p class="MsoNormal">print “Full Name=`full_name“$FIRST” “$LAST”`”</p>
<p class="MsoNormal">Or, you can use the non-deprecated form presented in the previous example.</p>
<p class="MsoNormal">One other concern is how to successfully call Boolean functions in an ‘if’ call.  Here’s a simple example:</p>
<p class="MsoNormal">if [[ test_name “henry” “henry” &amp;&amp; “$ME” = “henry” ]]</p>
<p class="MsoNormal">then</p>
<p class="MsoNormal" style="padding-left:30px;">print “hi henry”</p>
<p class="MsoNormal">fi</p>
<p class="MsoNormal">This won’t work!  The Boolean and the non-boolean portions need to be separated.  So, here’s the correct way to combine the two:</p>
<p class="MsoNormal">if test_name “henry” “henry” &amp;&amp; [[“$ME” = “henry” ]]</p>
<p class="MsoNormal">then</p>
<p class="MsoNormal" style="padding-left:30px;">print “hi henry”</p>
<p class="MsoNormal">fi</p>
<p class="MsoNormal">Hopefully this blog entry has encouraged the use of functions in shell scripting.  Thanks.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/unbeta.wordpress.com/10/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/unbeta.wordpress.com/10/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/unbeta.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/unbeta.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/unbeta.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/unbeta.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/unbeta.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/unbeta.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/unbeta.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/unbeta.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/unbeta.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/unbeta.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/unbeta.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/unbeta.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/unbeta.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/unbeta.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=unbeta.wordpress.com&amp;blog=2063191&amp;post=10&amp;subd=unbeta&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://unbeta.wordpress.com/2008/07/20/korn-shell-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/333e31e2c8f8fa7759ae6dc8c97fc733?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">unbeta</media:title>
		</media:content>
	</item>
		<item>
		<title>Awk Tips</title>
		<link>http://unbeta.wordpress.com/2007/12/27/awk-tips/</link>
		<comments>http://unbeta.wordpress.com/2007/12/27/awk-tips/#comments</comments>
		<pubDate>Thu, 27 Dec 2007 20:54:19 +0000</pubDate>
		<dc:creator>unbeta</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://unbeta.wordpress.com/2007/12/27/awk-tips/</guid>
		<description><![CDATA[Return all fields to the right of a particular field: echo &#8220;testing&#124;1&#124;2&#124;3&#124;4&#8243; &#124; awk -F \&#124; &#8216;{for (i=3;i&#60;NF+1;i++) o = (o FS $i)} END {print substr(o,2)}&#8217; or echo &#8220;testing&#124;1&#124;2&#124;3&#124;4&#8243; &#124; awk -F \&#124; &#8216;{print substr($0, index($0,$3)) }&#8217;  (See original link) results in: &#8217;2&#124;3&#124;4&#8242; or starting with the third field, all fields to the right. To [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=unbeta.wordpress.com&amp;blog=2063191&amp;post=9&amp;subd=unbeta&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="left">Return all fields to the right of a particular field:</p>
<div>
<blockquote><p>echo &#8220;testing|1|2|3|4&#8243; | awk -F \| &#8216;{for (i=3;i&lt;NF+1;i++) o = (o FS $i)} END {print substr(o,2)}&#8217;</p>
<p>or</p>
<p>echo &#8220;testing|1|2|3|4&#8243; | awk -F \| &#8216;{print substr($0, index($0,$3)) }&#8217;  (See original <a href="http://www.linuxquestions.org/questions/linux-newbie-8/awk-print-field-to-end-and-character-count-179078/">link</a>)</p>
<p>results in: &#8217;2|3|4&#8242; or starting with the third field, all fields to the right.</p></blockquote>
</div>
<p align="left">To format an integer with comma-separators:</p>
<div>
<blockquote><p>echo &#8220;123456&#8243; | awk &#8216;{for (i=1;i&lt;length($0)+1;i++) if ((!(i%3)) &amp;&amp; (i!=length($0))) o = (&#8220;,&#8221; substr($0,length($0)-i+1,1) o); else o = (substr($0,length($0)-i+1,1) o)} END {print o}&#8217;</p></blockquote>
<blockquote><p>results in &#8217;123,456&#8242;</p></blockquote>
</div>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/unbeta.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/unbeta.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/unbeta.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/unbeta.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/unbeta.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/unbeta.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/unbeta.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/unbeta.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/unbeta.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/unbeta.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/unbeta.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/unbeta.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/unbeta.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/unbeta.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/unbeta.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/unbeta.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=unbeta.wordpress.com&amp;blog=2063191&amp;post=9&amp;subd=unbeta&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://unbeta.wordpress.com/2007/12/27/awk-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/333e31e2c8f8fa7759ae6dc8c97fc733?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">unbeta</media:title>
		</media:content>
	</item>
		<item>
		<title>Oracle RDBMS Tips</title>
		<link>http://unbeta.wordpress.com/2007/11/12/oracle-rdbms-tips/</link>
		<comments>http://unbeta.wordpress.com/2007/11/12/oracle-rdbms-tips/#comments</comments>
		<pubDate>Mon, 12 Nov 2007 19:41:50 +0000</pubDate>
		<dc:creator>unbeta</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://unbeta.wordpress.com/2007/11/12/oracle-rdbms-tips/</guid>
		<description><![CDATA[Two-phase commit views: dba_2pc_neighbors dba_2pc_pending To kill all non-local database connections in UNIX: ps -ef &#124; grep LOCAL=NO &#124; grep ${ORACLE_SID} &#124; awk &#8216;{print $2}&#8217; &#124; while read pid; do kill -9 $pid; done<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=unbeta.wordpress.com&amp;blog=2063191&amp;post=8&amp;subd=unbeta&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Two-phase commit views:</p>
<blockquote><p>dba_2pc_neighbors</p>
<p>dba_2pc_pending</p></blockquote>
<p>To kill all non-local database connections in UNIX:</p>
<blockquote><p>ps -ef | grep LOCAL=NO | grep ${ORACLE_SID} | awk &#8216;{print $2}&#8217; | while read pid; do kill -9 $pid; done</p></blockquote>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/unbeta.wordpress.com/8/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/unbeta.wordpress.com/8/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/unbeta.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/unbeta.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/unbeta.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/unbeta.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/unbeta.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/unbeta.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/unbeta.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/unbeta.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/unbeta.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/unbeta.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/unbeta.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/unbeta.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/unbeta.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/unbeta.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=unbeta.wordpress.com&amp;blog=2063191&amp;post=8&amp;subd=unbeta&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://unbeta.wordpress.com/2007/11/12/oracle-rdbms-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/333e31e2c8f8fa7759ae6dc8c97fc733?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">unbeta</media:title>
		</media:content>
	</item>
	</channel>
</rss>
