Shell variable is not working


 
Thread Tools Search this Thread
Operating Systems AIX Shell variable is not working
# 1  
Old 11-01-2012
Shell variable is not working

One of my shell script, I'm using shell variable to substitute parameter value to a oracle related command "tnsping". without substitution same value is working fine. see below example.

Below is the result is expected with command:

> tnsping "(ADDRESS = (PROTOCOL = TCP)(HOST = uedcb031)(PORT = 1521))"

TNS Ping Utility for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production on 01-NOV-2012 19:28:42

Copyright (c) 1997, 2011, Oracle. All rights reserved.

Attempting to contact (ADDRESS = (PROTOCOL = TCP)(HOST = uedcb031)(PORT = 1521))
OK (0 msec)




my shell variable have below value

> echo $p
"(ADDRESS = (PROTOCOL = TCP)(HOST = uedcb031)(PORT = 1521))"


When I'm executing tnsping command with same variable, I'm not getting same result:
> tnsping $p

TNS Ping Utility for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production on 01-NOV-2012 19:28:25

Copyright (c) 1997, 2011, Oracle. All rights reserved.

Used parameter files:
/oracle/product/11.2/network/admin/sqlnet.ora

TNS-03505: Failed to resolve name

Can you please tell me how to correct this or if I'm wrong somewhere.
# 2  
Old 11-01-2012
Use double quote:-

Code:
tnsping "$p"

# 3  
Old 11-01-2012
tnsping "$p" also not working as expected

Code:
> tnsping "$p"

TNS Ping Utility for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production on 01-NOV-2012 19:46:42

Copyright (c) 1997, 2011, Oracle.  All rights reserved.

Used parameter files:
/oracle/product/11.2/network/admin/sqlnet.ora

TNS-03505: Failed to resolve name

# 4  
Old 11-01-2012
Looks like you have double quotes in your variable p value:

Code:
"(ADDRESS = (PROTOCOL = TCP)(HOST = uedcb031)(PORT = 1521))"

Reassign the variable p value to:-

Code:
p="(ADDRESS = (PROTOCOL = TCP)(HOST = uedcb031)(PORT = 1521))"

echo $p and make sure it does not have a double quote:-

Code:
echo $p
(ADDRESS = (PROTOCOL = TCP)(HOST = uedcb031)(PORT = 1521))

Retry:-

Code:
tnsping "$p"

I hope it helps.

---------- Post updated at 14:58 ---------- Previous update was at 14:54 ----------

Or you can try:-

Code:
tnsping "`echo $p | sed 's/\"//g'`"

This User Gave Thanks to Yoda For This Post:
# 5  
Old 11-01-2012
WOW !!
many thanks !! following way its working now.

Code:
[:-/oracle/product/11.2/auto-dwhsu] p="(ADDRESS = (PROTOCOL = TCP)(HOST = uedcb031)(PORT = 1521))"
> echo $p
(ADDRESS = (PROTOCOL = TCP)(HOST = uedcb031)(PORT = 1521))
> tnsping "$p"

TNS Ping Utility for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production on 01-NOV-2012 20:04:14

Copyright (c) 1997, 2011, Oracle.  All rights reserved.

Attempting to contact (ADDRESS = (PROTOCOL = TCP)(HOST = uedcb031)(PORT = 1521))
OK (30 msec)

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep with variable not working

Hello, I am using below code : export ORAR=orp712z.int.thomsonreuters.com #echo $ORAR; if echo $ORAR|grep -i "_" then ORACLE_SID1= echo $ORAR|cut -f2 -d "_" echo $ORACLE_SID1 ORACLE_SID=fgrep "$ORACLE_SID1" /etc/oratab|cut -f1 -d ":" #echo $ORACLE_SID else ORACLE_SID1= echo $ORAR|cut... (1 Reply)
Discussion started by: admin_db
1 Replies

2. Shell Programming and Scripting

Cp not working in shell script but running perfectly from shell

Dear All, I have script. Dest="" IFS=' ' for translation in $(echo $MY_MAP) do t1=$(echo $translation | cut -d"=" -f1) t2=$(echo $translation | cut -d"=" -f2| cut -d"," -f1) if then Dest=$UNX/$u_product_path/$u_study_path/$UNXTR/$t2 break; ... (4 Replies)
Discussion started by: yadavricky
4 Replies

3. Shell Programming and Scripting

Variable is not working

Hello Friends I want to create a bash script to ping my server but its not working as per my below code #!/bin/bash AA=AA1xx.example.com BB=BB1xx.example.com ping -c 3 $`hostname|cut -c-2` Error: ping: unknown host $BB Can any one help me to resolve this . Thank you (10 Replies)
Discussion started by: nith_anandan
10 Replies

4. Shell Programming and Scripting

export variable not working after su

I have a requirement to change user inside a shell script and execute group of commands. I have done it many times earlier but never came across the issue with exporting variables. Strangely if a var is exported afetr su, it is not working where as if it is does outside su, it works. Another issue... (8 Replies)
Discussion started by: sasiharitha
8 Replies

5. Shell Programming and Scripting

export of a variable isn't working

Hi I want export input data ... echo "month: " read m export m=$m also export m is not working ? the month-variable should be exportet for the use in other scripts, but it is not working like this. What i'm doing wrong? Thanks in advance! IMPe (10 Replies)
Discussion started by: IMPe
10 Replies

6. Shell Programming and Scripting

A simple variable subst is not working

Hi what i want: listing files in a special range ls -lrt 20120601{05..06}* ... -rw-rw-r-- 1 imp imp 279 1. Jun 07:51 201206010550 -rw-rw-r-- 1 imp imp 279 1. Jun 07:01 201206010600 -rw-rw-r-- 1 imp imp 279 1. Jun 07:11 201206010610 -rw-rw-r-- 1 imp imp 279 1. Jun 07:21... (1 Reply)
Discussion started by: IMPe
1 Replies

7. UNIX for Dummies Questions & Answers

grep'ing a variable - why not working

Hi all, Am writing a ksh script where I am looking for processes that has gone defunct and all of which has the same PPID PID is the variable that I need to match as this is the process ID of the processes that has gone defunct Am just curious how come the following DOES NOT work? ps... (6 Replies)
Discussion started by: newbie_01
6 Replies

8. Shell Programming and Scripting

Variable not working correctly.

Hi, I have a script where I am trying to set a local variable using the following, MYVAR="$NAME"_"$NAME2".txt where say, NAME = one NAME2 = two so I want the output one_two.txt but what I am getting is, two.txt basically the $NAME2 is overwriting, what am I doing wrong? ... (3 Replies)
Discussion started by: walsh_j
3 Replies

9. Shell Programming and Scripting

Basic variable expansion not working...

#!/usr/bin/bash if then echo "Not valid arguments entered. Just username should be entered." else USER_NAME=$1 FILE_NAME=$USER_NAME.info UNN=STUDIN\\\\$1 echo $UNN last STUDIN\\\\$1 last UNN If I type `last STUDIN\\eip060` it works but if I try to expand it with variable it is... (5 Replies)
Discussion started by: Zammy_bg
5 Replies

10. Shell Programming and Scripting

assign value to variable is not working

Hi :) The next script campares two files File1-Line1 vs File2-Line1, File1-Line1 vs File2-Line2... only if line contains "AS-", if LineX is not in File2 writes in aux, but "valor" is allways=1 never changes! :confused: What is wrong? valor changes to 0 before break, after brake is again 1 ... (3 Replies)
Discussion started by: agustincm
3 Replies
Login or Register to Ask a Question