LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Script creation(How to validate SID?) (https://www.linuxquestions.org/questions/linux-newbie-8/script-creation-how-to-validate-sid-826478/)

pinga123 08-16-2010 02:22 AM

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.

Tinkster 08-16-2010 03:39 AM

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

pinga123 08-16-2010 04:56 AM

Quote:

Originally Posted by Tinkster (Post 4067523)
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?

Tinkster 08-16-2010 01:01 PM

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

pinga123 08-16-2010 11:06 PM

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



All times are GMT -5. The time now is 02:48 PM.