Issue with script in linux but in unix works


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issue with script in linux but in unix works
# 1  
Old 04-30-2010
Issue with script in linux but in unix works

I have this simple script:

Code:
#! /usr/bin/sh
#*****************************************************************************
# *** get_input (question variable) ***
#*****************************************************************************
get_input ()
{
echo "${BOLD}${1} : "
read INPUT_VAR
echo "${OFF}"
export ${2}_INPUT=$INPUT_VAR
}
# End of get_input ()
#*****************************************************************************
# *** end get_input (question variable) ***
#*****************************************************************************
get_input "Please provide instance name (e.g. backp101) " INSTANCE
export INSTANCE_INPUT=`echo $INSTANCE_INPUT | awk '{print tolower( $1 )}'`
export INSTANCE=`echo $INSTANCE_INPUT`
DATABASE_CHECK_OK=N
cat /opt/oracle/admin/etc/oratab | while read line
do
   INSTANCE_CHECK=`echo $line | cut -c 1-8`
if [ "$INSTANCE_CHECK" = "$INSTANCE_INPUT" ]
then
   echo "Y"
   DATABASE_CHECK_OK=Y
   break
else
   echo "N"
   DATABASE_CHECK_OK=N
fi
done
echo "DATABASE_CHECK_OK:" $DATABASE_CHECK_OK

the problem is with the variable DATABASE_CHECK_OK
if the variable get DATABASE_CHECK_OK = Y (change the value inside the if)
and the while ends the variable still having N as value Smilie
this is the output that I'm getting:
Code:
Please provide instance name (e.g. backp101)  :
eddyt101 <-- input value
N
N
Y
DATABASE_CHECK_OK: N

this is the oratab content:
Code:
bryat101:/opt/oracle/product/11.2.0.1:N
bryat201:/opt/oracle/product/11.2.0.1:Y
eddyt101:/opt/oracle/product/11.2.0.1:N
mirlt101:/opt/oracle/product/11.2.0.1:Y

sorry for my english Smilie hope you can understand Smilie

any help in what is wrong? the script is working OK in HPUX
this is the so version:
Code:
Linux etlx1103.eu.pg.com 2.6.18-128.el5 #1 SMP Wed Dec 17 11:41:38 EST 2008 x86_64 x86_64 x86_64 GNU/Linux


Last edited by Scott; 05-01-2010 at 04:45 PM.. Reason: Code tags, please...
# 2  
Old 04-30-2010
Quote:
Originally Posted by C|KiLLeR|S
I have this simple script:

Please put code inside [code] tags.
Quote:
Code:
#! /usr/bin/sh
#*****************************************************************************
# *** get_input (question variable) ***
#*****************************************************************************
get_input ()
{
echo "${BOLD}${1} : "
read INPUT_VAR
echo "${OFF}"
export ${2}_INPUT=$INPUT_VAR
}
# End of get_input ()
#*****************************************************************************
# *** end get_input (question variable) ***
#*****************************************************************************
get_input "Please provide instance name (e.g. backp101) " INSTANCE
export INSTANCE_INPUT=`echo $INSTANCE_INPUT | awk '{print tolower( $1 )}'`
export INSTANCE=`echo $INSTANCE_INPUT`
DATABASE_CHECK_OK=N
cat /opt/oracle/admin/etc/oratab | while read line


In most shells, all elements of a pipeline are executed in a subshell.

Use redirection instead:
Code:
while read line
do
  : whatever
done < /opt/oracle/admin/etc/oratab

Quote:
any help in what is wrong? the script is working OK in HPUX
this is the so version:
Linux etlx1103.eu.pg.com 2.6.18-128.el5 #1 SMP Wed Dec 17 11:41:38 EST 2008 x86_64 x86_64 x86_64 GNU/Linux

On HPUX you are probably using ksh.
# 3  
Old 04-30-2010
Here is a simpler solution:

Code:
#!/bin/ksh

echo "Please input instance name:"
read my_instance
grep -i "^$my_instance:"  /opt/oracle/admin/etc/oratab 2>&1 > /dev/null

rc=$?

if (( $rc == 0 )); then
  echo "DATABASE_CHECK_OK: Y"
else
  echo "DATABASE_CHECK_OK: N"
fi

Hopefully, this will work on all platforms.
# 4  
Old 04-30-2010
yupiiiiiii
thanks it works
Smilie

but looks like now isn't working on unix Smilie
need the script working in both environmets...
# 5  
Old 04-30-2010
Quote:
Originally Posted by soleil4716
Here is a simpler solution:

Code:
#!/bin/ksh

echo "Please input instance name:"
read my_instance
grep -i "^$my_instance:"  /opt/oracle/admin/etc/oratab 2>&1 > /dev/null

rc=$?

if (( $rc == 0 )); then


That is not standard; it will not work everywhere.

Code:
if [ $rc = 0 ]; then

Quote:
Code:
  echo "DATABASE_CHECK_OK: Y"
else
  echo "DATABASE_CHECK_OK: N"
fi


Or:

Code:
if grep -i "^$my_instance:"  /opt/oracle/admin/etc/oratab 2>&1 > /dev/null
then
   ...

# 6  
Old 04-30-2010
sorry my mistake, cfajohnson's solution works in both environments Smilie
thanks cfajohnson Smilie
saved me a lot of time... Smilie

pura vida Smilie
# 7  
Old 04-30-2010
In HP-UX /usr/bin/sh is the Posix shell.
Should the O/P shebang positively specify /usr/bin/bash for GNU/Linux? Just an idea, not checked. Even specifying /bin/ksh doesn't guarantee portability nowadays.

cfajohnson's "if test" tackles the main issue and any sub-issues caused by comment lines in oratab files.


Quote:
but looks like now isn't working on unix
Please post the script you ran, the answers you typed, and the response you saw.



Just read the O/P post and there is no need to answer my questions because cfajohnson's solution is portable.

Last edited by methyl; 04-30-2010 at 08:09 PM.. Reason: O/P typing at same time as me!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Expect scripting issue, works interactively when doing commands in cli, does not work in script

Hi; problem may be obvious, simple but I have to say it is somehow not easy to locate the issue. I am doing some word extracting from multiline text. Interacting in CLI seems to work without issues. First step is to add multiline text to a variable. expect1.1> expect1.1> set... (2 Replies)
Discussion started by: aldowski
2 Replies

2. Shell Programming and Scripting

Why statement works in LINUX and not UNIX?

Hello, I have a ksh script that uses code below. For some reason it works under linux but fails in unix. Any idea why? if ]; then ... Thanks (9 Replies)
Discussion started by: rdogadin
9 Replies

3. Shell Programming and Scripting

Script works with Linux not with Solaris

Hi I have the following script which works in Linux shell but gives issues with Sun OS Solaris 5.10, What i am trying to achieve here is we have a list of file names in list.txt file and we parse each file at a time for a particular pattern and copt next 4 lines after we hit the pattern to a... (6 Replies)
Discussion started by: Yugendra
6 Replies

4. Shell Programming and Scripting

sed works on Linux and Unix does not work

Hi, I use this command in Linux but if I run the same command does not work in freebsd. Follow the below command: Linux works: sed -e '1731a\' -e '####' squid.conf > squid2.conf ; sed -e '1731a\' -e 'acl TESTE_ip src 192.168.1.1/255.255.255.255' squid2.conf > squid.conf ; sed -e... (7 Replies)
Discussion started by: andreirp
7 Replies

5. UNIX for Dummies Questions & Answers

FTP that works correctly in command prompt and shows issue in UNIX server

Hi All, FTP ports opens with the given user name and password and allows to download file through COMMAND PROMPT. Code as below: H:\>ftp ftpxxxxx Connected to entvc2ft07-pub.xxxxx.com. 220 Microsoft FTP Service User (entvc2ft07-pub.xxxxx.com:(none)): userxxxxx 331 User name okay, need... (1 Reply)
Discussion started by: vijayalakshmi.r
1 Replies

6. Shell Programming and Scripting

Works in shell but not script UNIX

ok i have a very simple UNIX script #!/bin/bash TERM=ansi;export TERM PFCMARK=25;export PFCMARK umask 0000 PFUMASK=000;export PFUMASK #run for filepro menus and exectuables echo "###########File Modification Log.############\r" > "/public/appl-fp$(date +%m-%d-%Y).txt" find /appl/fp/... (10 Replies)
Discussion started by: dunpealslyr
10 Replies

7. Shell Programming and Scripting

Execution issue with shell script - works in a different environment

Hi I get the following error while executing the shell script. I did not get an error when I ran the script in a different environment (unix server). str-token.ksh: 0403-057 Syntax error at line 20 : `(' is not expected. This is the line which gives error string=(${pos_array}) Please find... (3 Replies)
Discussion started by: hidnana
3 Replies

8. UNIX for Dummies Questions & Answers

what's the Linux|Unix OSes works on Servers

Hi everybody , I'm new here in the forum and new Dummy in L|U systems (Hope finding welcomes...:)). I just want to ask : What is the OS's that works on servers and the OS's that work as client OS?? I just know that Solaris Work on sarvers :D.. and i'm glad to be memmber in this... (1 Reply)
Discussion started by: derbi
1 Replies

9. Shell Programming and Scripting

Script works on Solaris, not on Linux

I'm in the same boat as Barbus - same exercis (https://www.unix.com/shell-programming-scripting/43609-processes-users.html) The following script works on a solaris server I have access to. It doesn't however, work on the companies Linux machine. Any idea what's up? I have very little shell... (1 Reply)
Discussion started by: Silverhood
1 Replies

10. Shell Programming and Scripting

Script works on Solaris, not on Linux

I'm in the same boat as Barbus - same exercis (https://www.unix.com/shell-programming-scripting/43609-processes-users.html) The following script works on a solaris server I have access to. It doesn't however, work on the companies Linux machine. Any idea what's up? I have very little shell... (0 Replies)
Discussion started by: Silverhood
0 Replies
Login or Register to Ask a Question