LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-16-2010, 03:22 AM   #1
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Rep: Reputation: 36
Script creation(How to validate SID?)


I was going write a script from following site.
http://www.thegeekstuff.com/2010/07/...cle-sql-query/
My configuration setting for oracle XE.
Quote:
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.
Quote:
sid_dir=`echo $ORACLE_HOME | sed -n 's@^\(\/[^\/]\+\/\).*$@\1@;p'`
Quote:
$ 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.
Quote:
/usr/lib/oracle/xe/oradata
Please suggest.

Last edited by pinga123; 08-16-2010 at 03:25 AM.
 
Old 08-16-2010, 04:39 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Did you actually try to run these two outside a script?
Code:
export ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
echo $ORACLE_HOME | sed -n 's@^\(\/[^\/]\+\/\).*$@\1@;p'
?

This actually gives sid_dir=/usr

There's no oradata under /usr
 
Old 08-16-2010, 05:56 AM   #3
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by Tinkster View Post
Did you actually try to run these two outside a script?
Code:
export ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
echo $ORACLE_HOME | sed -n 's@^\(\/[^\/]\+\/\).*$@\1@;p'
?

This actually gives sid_dir=/usr

There's no oradata under /usr
You got it right .I m confused how would i validate ORACLE_SID?
Means how would i come to the conclusion that the ORACLE_SID is correct or not?
 
Old 08-16-2010, 02:01 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Haven't actually installed/used Oracle in over 5 years, so
am rather rusty. If I remember correctly the sid isn't necessarily
part of the directory structure, so the only way to test for
it would be to try and connect; evaluate the result, and
complain if it fails.



Cheers,
Tink
 
Old 08-17-2010, 12:06 AM   #5
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
Hi all I got this nice suggestion from other forum so i thought of sharing it here for others.

Little Drawback of below script:
You will need to have a different for different oracle product.
This is because they maintain different naming convention for the process.
in case of xe they reffer it as xe_smon_<ORACLE_SID>
where as other distribution reffer it as ora_smon_<ORACLE_SID>

For Oracle XE installation.(Tested and working fine)

Code:
SID=`ps -ef|grep smon|grep -v grep|awk '{print $8}'`

if [ 'xe_smon_'$ORACLE_SID != $SID ] ; then
echo "ORACLE_SID IS NOT SET"
exit 1
fi
For Other Installation(Not Tested but should work.)

Code:
SID=`ps -ef|grep smon|grep -v grep|awk '{print $8}'`

if [ 'ora_smon_'$ORACLE_SID != $SID ] ; then
echo "ORACLE_SID IS NOT SET"
exit 1
fi

Last edited by pinga123; 08-17-2010 at 12:13 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script creation (how to include options in the script) pinga123 Linux - Newbie 7 07-15-2010 06:56 AM
Validate and sort input in script stuaz Programming 5 08-26-2009 05:18 PM
URGENT: Please validate this script PKrishna Linux - Newbie 1 04-01-2008 12:03 PM
User Creation Script mfaisalkh Programming 1 08-06-2007 04:57 AM
script creation woes mrgreaper Linux - Newbie 10 06-20-2006 08:41 AM


All times are GMT -5. The time now is 09:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration