Script creation(How to validate SID?)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script creation(How to validate SID?)
# 1  
Old 08-16-2010
Script creation(How to validate SID?)

I was going write a script from following site.
Unix Shell Script to Execute Oracle SQL Query (link removed)

My configuration setting for oracle XE.
Code:
export ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID=XE

but after setting a proper oracle_sid its still giving me an error.
I doubt there is a wrong command to validate the sid.
i.e.
Code:
sid_dir=`echo $ORACLE_HOME | sed -n 's@^\(\/[^\/]\+\/\).*$@\1@;p'`

Code:
$ cat sql_query.sh
#!/bin/bash
# Validate the value of ORACLE_HOME #
# If ORACLE_HOME is empty #
if [ -z $ORACLE_HOME ]
then
        echo "Set the ORACLE_HOME variable"
        exit 1
fi
# If ORACLE_HOME doesn't exist #
if [ ! -d $ORACLE_HOME ]
then
        echo "The ORACLE_HOME $ORACLE_HOME does not exist"
        exit 1
fi
# Validate the value of ORACLE_SID #
if [ -z $ORACLE_SID ]
then
        echo "Set the ORACLE_SID variable"
        exit 1
fi
sid_dir=`echo $ORACLE_HOME | sed -n 's@^\(\/[^\/]\+\/\).*$@\1@;p'`
# Check the given ORACLE_SID is valid.
if [ ! -d $sid_dir/oradata/$ORACLE_SID ]
then
        echo "The ORACLE_SID is invalid"
        exit 1
fi

location of oradata directory.
Code:
/usr/lib/oracle/xe/oradata

Please suggest.

Last edited by Scott; 08-16-2010 at 11:15 AM.. Reason: Replaced QUOTE tags with CODE tags
# 2  
Old 08-16-2010
your "sid_dir" variable contain the value "/usr/" after below command. There is no need to put one more slash.

sid_dir=`echo $ORACLE_HOME | sed -n 's@^\(\/[^\/]\+\/\).*$@\1@;p'`

Code:
if [ ! -d $sid_dir/oradata/$ORACLE_SID ]
then
echo "The ORACLE_SID is invalid"
exit 1
fi

# 3  
Old 08-16-2010
Quote:
Originally Posted by pravin27
your "sid_dir" variable contain the value "/usr/" after below command. There is no need to put one more slash.

sid_dir=`echo $ORACLE_HOME | sed -n 's@^\(\/[^\/]\+\/\).*$@\1@;p'`

Code:
if [ ! -d $sid_dir/oradata/$ORACLE_SID ]
then
echo "The ORACLE_SID is invalid"
exit 1
fi

path /usr/oradata doesn't exists.
i want to make it more general .IS there any script which will validate sid on any oracle distribution?
# 4  
Old 08-16-2010
I didn't read your sh script, since I usually don't bother with code that isn't indented (no offense, life is just too short Smilie). However, I did notice that the highlighted sed command's basic regular expression (BRE) violates the POSIX standard. It may work with some implementations and not with others.
Code:
sed -n 's@^\(\/[^\/]\+\/\).*$@\1@;p'

Since in that context "/" is an ordinary character, that sed s command violates section 9.3.2 regarding BREs. See Regular Expressions for more info.

If this is your problem, changing "\/" to "/" should fix it. If that's not your problem, it's probably still a good idea to make that change to avoid future problems, should the sed implementation change at some future time.

Regards,
Alister

Last edited by alister; 08-16-2010 at 11:47 AM.. Reason: removed irrelevant text
# 5  
Old 08-16-2010
Worth a look at contents of the supplied script. Amongst other things it checks /etc/oratab for valid SID.

Code:
${ORACLE_HOME}/bin/dbhome

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to validate header in a csv file

Hi All; I am struggling to write a script that validates file header. Header file would be like below with TAB separated TRX # TYPE REF # Source Piece Code Destination Piece Code every time I need to check the txt file if the header was same as above fields if validation success... (6 Replies)
Discussion started by: heye18
6 Replies

2. AIX

Script to validate between two environments

Hi, I trust that you are well - I'm a bit new into AIX and I've been assigned a task to write a script that will always validate between our two Prod (Prod A and Prod B) environments to confirm which prod we live at. The two environments are exact replicas and this check I need to put in... (5 Replies)
Discussion started by: Twaggzk
5 Replies

3. Shell Programming and Scripting

Need script to validate file according to date

Hi All, I am very new to unix and just started to work with unix and shell scripting.I have a query anyone help would be much appreciated I am using sun solaris OS I want to validate a file according to its date and if validate successful then it would write the file name,size,date and... (3 Replies)
Discussion started by: sv0081493
3 Replies

4. Shell Programming and Scripting

Script to validate file header and trailer

Hi, I need a script that validates a file header/detail/trailer. File layout is: Header - Rec_Type|File_name|File_Date Detail - Rec_Type|field1|field2|field3... Trailder - Rec_Type|File_name|File_Date|Record_count Sample Data: HDR|customer_data.dat|20120709... (7 Replies)
Discussion started by: ash_sh
7 Replies

5. Shell Programming and Scripting

Please help me validate script

Hi Guys, Im a newbie to scripting and have a small assignment. can someone please confirm if the script i have written would work fine as we dont have a test server to test :( Scenario - copy 2 files from an ftp server (windows) to a linux machine (a perticular folder). run 2 different... (0 Replies)
Discussion started by: nishantvshah
0 Replies

6. Shell Programming and Scripting

How to Create LOG and Validate for this Script

Hi all, This is my Script #!/bin/bash current_date=`date +%d-%m-%Y_%H.%M.%S` Date=`date +%d%m%Y` Lfriday=`date +%d%m%Y -d last-friday` RootPath=/var/domaincount/com mysql zonefile<<EOFMYSQL CREATE TABLE com$Date(domain VARCHAR(255),col2 VARCHAR(255),col3 VARCHAR(255),col4... (10 Replies)
Discussion started by: anishkumarv
10 Replies

7. Shell Programming and Scripting

Validate BASH script before running it...

Hello, Is there some way to validate a bash script before running it. I want to make sure all of the syntax and everything is good so that I dont get a false return code. Thanks, tom (7 Replies)
Discussion started by: tjones1105
7 Replies

8. UNIX for Dummies Questions & Answers

. oraenv vs setdb [SID]

Hi, i am working on Tru64 os... When i try to connect to an Oracle instance, the usual method i follow is chsxsora1:oracle:PRD1 > . oraenv ORACLE_SID = ? PRD1 But for one Instance it was not working, chsxsora2:oracle:TST2 > . oraenv ORACLE_SID =*= ? TST2 i... (0 Replies)
Discussion started by: saharookiedba
0 Replies

9. UNIX Desktop Questions & Answers

Sid

What is SID and how to gahter information about that ?? Is this the right forum to ask this question ? If not then please help me out.. (6 Replies)
Discussion started by: risshanth
6 Replies

10. Shell Programming and Scripting

Need Script to Validate and Add more users one time

I need a script to validate and add more than one user at one time Field 1 - FirstName LastName Field 2 - userid Field 3 - email address Field 4 - department Validation for Field 1 No... (3 Replies)
Discussion started by: karthikn7974
3 Replies
Login or Register to Ask a Question