If condition fails, advise using wildcard


 
Thread Tools Search this Thread
# 1  
If condition fails, advise using wildcard

OS Environment: HP-UX B.11.31 U ia64

I am using the shell script code to connect to Oracle RAC database.
Passing the parameter of cluster database name.


Code:
typeset -l DB_ID=$1
+ typeset -l DB_ID=sivDB

#---- 3. SetDB validation -------------
if [ "$ORACLE_SID"x != "${DB_ID}"x ]; then
 print "============================"
 print " setdb failed for $db"
 print "============================"
 exit
fi

+ [ sivDB1x != sivDBx ]
+ print ========================================================
+ print  setdb failed for
 setdb failed for
+ print ========================================================
+ exit

Question:
Here I want the IF condition to succeed if first 5 characters of $ORACLE_SID matches with ${DB_ID}. Please advise.

For example: [ sivDB1x != sivDBx ]

Note: Actually I pass the Oracle RAC DB name. During the setdb ( setting the Oracle Environment ) it sets the instance running on the node like sivDB1 for Node1 and sivDB2 for Node 2 for the RAC DB of sivDB.
# 2  
Quote:
Originally Posted by Siva SQL
Question:
Here I want the IF condition to succeed if first 5 characters of $ORACLE_SID matches with ${DB_ID}. Please advise.
Code:
if [ "${ORACLE_SID:0:5}" == "$DB_ID" ]

# 3  
I am getting error as

"${ORACLE_SID:0:5}"x: bad substitution
# 4  
There is no character "x" in balajesuri's post.
What command did you issue?
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #983
Difficulty: Medium
The first official NetBSD release, NetBSD 0.1, was made on 9 April 1991.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If condition fails for special charecter

I have a sample server name listed in variable as below: var="server-13" I need to check if the 7th character on $var is number 1 whichenv=`echo "$var"| head -c 7 | tail -c 1` if ]; then echo "9 found" else echo "9 Not Found" fi Output: This works... (3 Replies)
Discussion started by: mohtashims
3 Replies

2. UNIX for Dummies Questions & Answers

Would you like to advise a beginner !

Im new in unix, I learned some commands, I have a small idea in MS Dos Would you like to advise me where and how to start ? (2 Replies)
Discussion started by: BaxxterHp
2 Replies

3. Shell Programming and Scripting

How to exit from shell script if above condition fails?

HI cd ${back_home} if above back_home does not exist, then script shoul exit. Please let us know how to do that (7 Replies)
Discussion started by: buzzme
7 Replies

4. Shell Programming and Scripting

If condition return 0 even when it fails to satisfy te condition

HI My doubt may be basic one but I need to get it clarified.. When i use "if" condition that checks for many AND, OR logical conditions like if ]; then return 0 fi Even the if condition fails it returns as zero.. Any clue.. But if i add else condition like if ]; ... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

5. Shell Programming and Scripting

redirect stdout echo command in condition A run in condition B

hi, I have some problems in my simple script about the redirect echo stdout command inside a condition. Why is the echo command inside the elif still execute in the else command Here are my simple script After check on the two diff output the echo stdout redirect is present in two diff... (3 Replies)
Discussion started by: jao_madn
3 Replies

6. HP-UX

Difference between [condition] and [[condition]] and ((condition)) when used with if condition

Executed the following if conditions .. and got different results . only (( )) gave correct o/p with all scenarios . Can anybody please let me know what is the difference between and ] and ((condition)) when used with if condition. And why each condition gave different result. 1.... (2 Replies)
Discussion started by: soumyabubun
2 Replies

7. Shell Programming and Scripting

Stop execution of script if some condition fails

After my if condtion give rusult true then script should stop execution. Please advice...Thnaks in advance (1 Reply)
Discussion started by: vivek1489
1 Replies

8. Linux

Please advise me.

Hello all, I have a question, and would like some advice please. I am a windows guy by trade....5 years in the Marines is where I learnt a lot of what i know. I took a junior level sys admin job...learned a bit more...and now I do IT security. All of this happened in the last 8 years. So I'm 27... (2 Replies)
Discussion started by: Quality
2 Replies

9. UNIX for Dummies Questions & Answers

Find wildcard .shtml files in wildcard directories and removing them- How's it done?

I'm trying to figure out how to build a small shell script that will find old .shtml files in every /tgp/ directory on the server and delete them if they are older than 10 days... The structure of the paths are like this: /home/domains/www.domain2.com/tgp/ /home/domains/www.domain3.com/tgp/... (1 Reply)
Discussion started by: Neko
1 Replies

Featured Tech Videos