<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: if then else script wont work with oracle command in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-script-wont-work-with-oracle-command/m-p/4896705#M403347</link>
    <description>There is no (obvious) reason why it should behave &lt;BR /&gt;differently. Run the script with debug mode &lt;BR /&gt;(i.e ksh -x script) and see if it helps you.&lt;BR /&gt;&lt;BR /&gt;- Biswajit&lt;BR /&gt;</description>
    <pubDate>Mon, 18 Apr 2005 17:55:06 GMT</pubDate>
    <dc:creator>Biswajit Tripathy</dc:creator>
    <dc:date>2005-04-18T17:55:06Z</dc:date>
    <item>
      <title>if then else script wont work with oracle command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-script-wont-work-with-oracle-command/m-p/4896704#M403346</link>
      <description>Hello,&lt;BR /&gt;    I am modifying an old bourne shell script in which there is a part that does:&lt;BR /&gt;sqlplus xxx/yyy &amp;lt;&amp;lt; EOF&lt;BR /&gt;select stuff from mytable&lt;BR /&gt;/&lt;BR /&gt;EOF&lt;BR /&gt;&lt;BR /&gt;This works fine, until I put it into a conditional statement:&lt;BR /&gt;if [ $1 = "PROD" ]&lt;BR /&gt;then&lt;BR /&gt;    sqlplus xxx/yyy &amp;lt;&amp;lt; EOF&lt;BR /&gt;    select stuff from mytable&lt;BR /&gt;    /&lt;BR /&gt;    EOF&lt;BR /&gt;else&lt;BR /&gt;    sqlplus xxx/yyy &amp;lt;&amp;lt; EOF&lt;BR /&gt;    select otherstuff from mytable&lt;BR /&gt;    /&lt;BR /&gt;    EOF&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;this fails with 'else' is not expected&lt;BR /&gt;why does this not work?</description>
      <pubDate>Mon, 18 Apr 2005 17:39:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-script-wont-work-with-oracle-command/m-p/4896704#M403346</guid>
      <dc:creator>Dave Chamberlin</dc:creator>
      <dc:date>2005-04-18T17:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: if then else script wont work with oracle command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-script-wont-work-with-oracle-command/m-p/4896705#M403347</link>
      <description>There is no (obvious) reason why it should behave &lt;BR /&gt;differently. Run the script with debug mode &lt;BR /&gt;(i.e ksh -x script) and see if it helps you.&lt;BR /&gt;&lt;BR /&gt;- Biswajit&lt;BR /&gt;</description>
      <pubDate>Mon, 18 Apr 2005 17:55:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-script-wont-work-with-oracle-command/m-p/4896705#M403347</guid>
      <dc:creator>Biswajit Tripathy</dc:creator>
      <dc:date>2005-04-18T17:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: if then else script wont work with oracle command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-script-wont-work-with-oracle-command/m-p/4896706#M403348</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I made this test:&lt;BR /&gt;&lt;BR /&gt;A=y&lt;BR /&gt;if [[ $A = "x" ]]&lt;BR /&gt;then&lt;BR /&gt;sqlplus system/manager &amp;lt;&lt;EOF&gt;&lt;/EOF&gt;select * from v\$backup where status = 'ACTIVE'&lt;BR /&gt;/&lt;BR /&gt;exit;&lt;BR /&gt;EOF&lt;BR /&gt;else&lt;BR /&gt;sqlplus system/manager &amp;lt;&lt;EOF&gt;&lt;/EOF&gt;select tablespace_name from dba_tablespaces&lt;BR /&gt;/&lt;BR /&gt;exit;&lt;BR /&gt;EOF&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;And it worked well.&lt;BR /&gt;I think you have some "strange" character, like backspace, inside your command.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;</description>
      <pubDate>Mon, 18 Apr 2005 18:55:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-script-wont-work-with-oracle-command/m-p/4896706#M403348</guid>
      <dc:creator>Julio Yamawaki</dc:creator>
      <dc:date>2005-04-18T18:55:14Z</dc:date>
    </item>
    <item>
      <title>Re: if then else script wont work with oracle command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-script-wont-work-with-oracle-command/m-p/4896707#M403349</link>
      <description>Dave,&lt;BR /&gt;try running your shell :&lt;BR /&gt;sh -x shell.sh PROD&lt;BR /&gt;This should help you debug what is happening.&lt;BR /&gt;&lt;BR /&gt;Perhaps you should check your EOF labels and rename the second set of EOFs to something else, add exits to the sqlplus statements and add -s after sqlplus to suppress banner.&lt;BR /&gt;&lt;BR /&gt;Regards</description>
      <pubDate>Tue, 19 Apr 2005 02:32:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-script-wont-work-with-oracle-command/m-p/4896707#M403349</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2005-04-19T02:32:02Z</dc:date>
    </item>
    <item>
      <title>Re: if then else script wont work with oracle command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-script-wont-work-with-oracle-command/m-p/4896708#M403350</link>
      <description>Hi Dave, try the POSIX syntax like Julio wrote. Just put the second heredoc at the beginning of the line, else it will not work.&lt;BR /&gt;If you like to use indentation, use a minus sign i.e.:&lt;BR /&gt;&lt;COMMAND&gt; &amp;lt;&amp;lt;-EOF &lt;BR /&gt;...&lt;BR /&gt;&lt;TAB&gt;EOF&lt;BR /&gt;to ignore leading tabs&lt;BR /&gt;&lt;BR /&gt;For security reasons, try sqlplus &amp;lt;&amp;lt; EOF&lt;BR /&gt;system/manager&lt;BR /&gt;EOF&lt;BR /&gt;or sqlplus /nolog &amp;lt;&lt;EOF&gt;&lt;/EOF&gt;connect system/manager&lt;BR /&gt;EOF&lt;BR /&gt;in stead of sqlplus system/manager &amp;lt;&amp;lt; OEF&lt;BR /&gt;...&lt;BR /&gt;EOF, because with an ps command the login/password will be shown &lt;BR /&gt;&lt;BR /&gt;You might try another construction:&lt;BR /&gt;case $1 in&lt;BR /&gt;  PROD)&lt;BR /&gt;    stmt="select 'blah' from dual; "&lt;BR /&gt;  ;;&lt;BR /&gt;  TEST&lt;BR /&gt;    stmt="select 'halb' from dual"&lt;BR /&gt;  ;;&lt;BR /&gt;esac&lt;BR /&gt;&lt;BR /&gt;sqlplus &amp;lt;&amp;lt; EOF&lt;BR /&gt;connect system/manager&lt;BR /&gt;$stmt;&lt;BR /&gt;EOF&lt;BR /&gt;&lt;BR /&gt;That's faster, because case is a shell built-in&lt;BR /&gt;&lt;BR /&gt;Hope this helps,&lt;BR /&gt;&lt;BR /&gt;Renarios&lt;/TAB&gt;&lt;/COMMAND&gt;</description>
      <pubDate>Tue, 19 Apr 2005 02:55:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-script-wont-work-with-oracle-command/m-p/4896708#M403350</guid>
      <dc:creator>renarios</dc:creator>
      <dc:date>2005-04-19T02:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: if then else script wont work with oracle command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-script-wont-work-with-oracle-command/m-p/4896709#M403351</link>
      <description>hi Dave,&lt;BR /&gt;i would check if no "strange characters" is polluing the script or a coma somewhere. that's often the problem !&lt;BR /&gt;don't you have a line error seeing by the shell ( "error line xx") ??&lt;BR /&gt;otherwise the debug will work fine for a command error or an in/out-put error&lt;BR /&gt;HTH&lt;BR /&gt;E.</description>
      <pubDate>Tue, 19 Apr 2005 05:37:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-script-wont-work-with-oracle-command/m-p/4896709#M403351</guid>
      <dc:creator>Etienne Roseau</dc:creator>
      <dc:date>2005-04-19T05:37:59Z</dc:date>
    </item>
    <item>
      <title>Re: if then else script wont work with oracle command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-script-wont-work-with-oracle-command/m-p/4896710#M403352</link>
      <description>Are you indenting the EOF within the if statement?  EOF must be the first characters on the line for it to end the sql command.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 19 Apr 2005 08:51:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-script-wont-work-with-oracle-command/m-p/4896710#M403352</guid>
      <dc:creator>Steve McKenna_3</dc:creator>
      <dc:date>2005-04-19T08:51:25Z</dc:date>
    </item>
    <item>
      <title>Re: if then else script wont work with oracle command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-script-wont-work-with-oracle-command/m-p/4896711#M403353</link>
      <description>One more thought..  and alternative way to do this..&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;if [ $1 = "PROD" ]&lt;BR /&gt;then&lt;BR /&gt;   stuff="whatever"&lt;BR /&gt;else&lt;BR /&gt;   stuff="whatever else"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;sqlplus xxx/yyy &amp;lt;&amp;lt; EOF&lt;BR /&gt;select ${stuff} from mytable&lt;BR /&gt;/&lt;BR /&gt;EOF&lt;BR /&gt;</description>
      <pubDate>Tue, 19 Apr 2005 08:54:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-script-wont-work-with-oracle-command/m-p/4896711#M403353</guid>
      <dc:creator>Steve McKenna_3</dc:creator>
      <dc:date>2005-04-19T08:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: if then else script wont work with oracle command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-script-wont-work-with-oracle-command/m-p/4896712#M403354</link>
      <description>Let me suggest a Plan B that avoids all the possible 'heredocs' syntax differences in shells that only get more complicated if you need to add a 3rd or 4th conditional branch.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#Create a temporary file&lt;BR /&gt;TDIR=${TMPDIR:-/var/tmp}&lt;BR /&gt;S1=${TDIR}/X${$}_1.sql&lt;BR /&gt;&lt;BR /&gt;trap '{eval rm -f ${S1}' 0 1 2 15 &lt;BR /&gt;# Trap forces removal of temp file upon exit&lt;BR /&gt;# or interrupt&lt;BR /&gt;&lt;BR /&gt;#Now simply use echo satements to build up #the sql file&lt;BR /&gt;&lt;BR /&gt;rm -f ${S1} # null the file&lt;BR /&gt;if [ "${1}" = "PROD" ]&lt;BR /&gt;  then&lt;BR /&gt;    echo "select stuff from mytable;" &amp;gt;&amp;gt; ${S1}&lt;BR /&gt;    echo "exit;" &amp;gt;&amp;gt; ${S1}&lt;BR /&gt;  fi&lt;BR /&gt;&lt;BR /&gt;# this could be extended as needed perhaps &lt;BR /&gt;# using a case statement rather than if's&lt;BR /&gt;&lt;BR /&gt;sqlplus xxx/yyy @${S1}&lt;BR /&gt;&lt;BR /&gt;# You don't need to remove the temp file&lt;BR /&gt;# The trap takes care of that for you.</description>
      <pubDate>Tue, 19 Apr 2005 09:13:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-script-wont-work-with-oracle-command/m-p/4896712#M403354</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2005-04-19T09:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: if then else script wont work with oracle command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-script-wont-work-with-oracle-command/m-p/4896713#M403355</link>
      <description>Thanks for the replies- the problem was combination of things - I rewrote without any indents and making sure no extra characters etc, and it works. I love unix but shells can be so tempermental on minor things like whitespace, indents, etc. Often I just write a C program to do what is needed - it is usually MUCH easier to deal with!</description>
      <pubDate>Tue, 19 Apr 2005 09:55:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-script-wont-work-with-oracle-command/m-p/4896713#M403355</guid>
      <dc:creator>Dave Chamberlin</dc:creator>
      <dc:date>2005-04-19T09:55:58Z</dc:date>
    </item>
  </channel>
</rss>

