bash problem

I have a ksh script with the following code and working fine under ksh.

IFS=$IFS
        IFS=:
        while read a b c
        do
                test "$a" = "$oraserver" && { orahome=$b; break; }
                echo $orahome
        done < /var/opt/oracle/oratab2
        IFS=$_IFS
        ORACLE_HOME=$orahome;export ORACLE_HOME

If I run this code under bash , it's setting ORACLE_HOME=''.

can somebody tell me what I am missing under bash or do I need to modify it for bash ?

Thanks

Hi.

What will work under both is:

test "$a" = "$oraserver" && orahome=$b && break

Thankyou .

I tried with the modified code , but, it's not working.

Same problem?

Perhaps if you said what $oraserver should be, and posted your oratab file (or the relevant part of it).....

here is the content of oratab file.

+ASM1:/opt/oracle/product/11.1.0/racasm:N
abcd1:/opt/oracle/product/11.1.0/racdb:N
xyz1:/opt/oracle/product/11.1.0/racdb:N

all I am trying to do is get the path from the above.
Thanks

Hi.

I would use awk... simpler!

orahome=$(awk -F: '$1 == "'$oraserver'" {print $2}'  /var/opt/oracle/oratab2)
ORACLE_HOME=$orahome;export ORACLE_HOME 

If $oraserver is set to one of +ASM1, abcd1 or xyz1 then it should work fine.

Nope . The awk solution is also not working.

Thanks

Hi.

I tested this and it works.

Please provide the following:

  • The exact code you are running
  • ls -l of /var/opt/oracle/oratab2
  • cat of /var/opt/oracle/oratab2
  • echo $oraserver
  • The exact output when you run the code.

Thanks.

oracle@testserver:/opt/dba/oraadmin/tools DEV$ cat /var/opt/oracle/oratab
#

# This file is used by ORACLE utilities. It is created by root.sh
# and updated by the Database Configuration Assistant when creating
# a database.

# A colon, ':', is used as the field terminator. A new line terminates
# the entry. Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
# $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively. The third filed indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
+ASM1:/opt/oracle/product/11.1.0/racasm:N
abc:/opt/oracle/product/11.1.0/racdb:N
def:/opt/oracle/product/11.1.0/racdb:N
ghi:/opt/oracle/product/11.1.0/racdb:N
jkl:/opt/oracle/product/10.2.0/racdb:N

orahome=$(awk -F: '$1 == "'$oraserver'" {print $2}' /var/opt/oracle/oratab2)
ORACLE_HOME=$orahome;export ORACLE_HOME

and it's returning ORACLE_HOME =''

I also tried like this ...

oracle@testserver:/opt/dba/oraadmin/tools DEV$ awk -F ":" '$1 == "'hmtrid1'" {print $2}' /var/opt/oracle/oratab

oracle@testserver:/opt/dba/oraadmin/tools DEV$

Thanks

---------- Post updated at 03:23 PM ---------- Previous update was at 03:23 PM ----------

it's working on KSH . I think u r testing it in ksh . Mine is bash .

Thanks

Hi talashil.

I've just tried it (again) in bash and it works.

The only thing I've learnt here is that I'm adding bash to my list of shells that I actively dislike! Give me the nice ksh (vi) editing command-line ways anyday!

Here's what I did:

I created a file called oratab2, adding what you said:

+ASM1:/opt/oracle/product/11.1.0/racasm:N
abcd1:/opt/oracle/product/11.1.0/racdb:N
xyz1:/opt/oracle/product/11.1.0/racdb:N

I set the variable oraserver:

oraserver=+ASM1

I ran the awk statement:

awk -F: '$1 == "'$oraserver'" {print $2}' oratab2

I got the output:

/opt/oracle/product/11.1.0/racasm

This works in ksh and bash.

If you really want tortured command-line editing, you can use "set -o vi" in bash, just as I can get an almost-usable command line in ksh with "set -o emacs".

I confess it was a cheap shot, and didn't add to the "knowledge base", but when you spend 90% of your life pressing escape-k, the up arrow just isn't where it needs to be when you need it!

that should work fine... can you post the output you are getting.. and the version of awk/nawk/gawk you are using?

Strange, here the script is working fine using ksh93, bash, dash(sh) and zsh