Home » Infrastructure » Unix » shell script in Solaris (Oracle 10g + Solaris 10)
shell script in Solaris [message #526154] Sun, 09 October 2011 08:06 Go to next message
dirish
Messages: 232
Registered: November 2006
Senior Member
Hi,

I am using Oracle Database 10g.

I have 1 OS user who is the owner of 2 Oracle Instances.

Each time i have to say export ORACLE_SID=test, ORACLE_SID=prod

I am writing a shell script (in a menu) for example to export test and prod databases.

In the shell script i have
exp system/testpassword full=y file=/test/export.dmp log=/test/export.log
&
exp system/testpassword full=y file=/prod/export.dmp log=/prod/export.log but i have to export the ORACLE_SID before.

How can i include this in the shell script?

Thanks
Dirish
Re: shell script in Solaris [message #526158 is a reply to message #526154] Sun, 09 October 2011 09:50 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
just do as below

export ORACLE_SID=test
exp system/testpassword full=y file=/test/export.dmp log=/test/export.log

export ORACLE_SID=prod
exp system/testpassword full=y file=/prod/export.dmp log=/prod/export.log but i have to export the ORACLE_SID before.
Re: shell script in Solaris [message #526167 is a reply to message #526154] Sun, 09 October 2011 13:38 Go to previous messageGo to next message
Michel Cadot
Messages: 68625
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
In 10g, better use expdp and not old exp.

Regards
Michel
Re: shell script in Solaris [message #526173 is a reply to message #526167] Sun, 09 October 2011 23:51 Go to previous messageGo to next message
dirish
Messages: 232
Registered: November 2006
Senior Member
Hi Michel,

Thanks for the advice. Actually the client wants to go with exp/imp.


Blackswan,
The first line in red is not working

vi exp_test.sh
export ORACLE_SID=test
echo "exp system/manager full=y file=/d02/exp_tst.dmp log=/d02exp_tst.log statistics=none" | su - ora10g

Please advise
Re: shell script in Solaris [message #526187 is a reply to message #526173] Mon, 10 October 2011 01:36 Go to previous messageGo to next message
Michel Cadot
Messages: 68625
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
When you "su -" you lose the current context and so the value of ORACLE_SID.
Put each export statement in a script and start this sript:

exp_test1.sh
export ORACLE_SID=test
exp system/testpassword full=y file=/test/export.dmp log=/test/export.log

exp_test.sh
su - ora10g -c exp_test1.sh

Regards
Michel
Re: shell script in Solaris [message #526188 is a reply to message #526154] Mon, 10 October 2011 01:37 Go to previous messageGo to next message
dirish
Messages: 232
Registered: November 2006
Senior Member
neither this one is working

vi exp_test.sh
echo "export ORACLE_SID=test" | su - ora10gecho "exp system/manager full=y file=/d02/exp_tst.dmp log=/d02exp_tst.log statistics=none" | su - ora10g

Re: shell script in Solaris [message #526195 is a reply to message #526187] Mon, 10 October 2011 01:57 Go to previous messageGo to next message
dirish
Messages: 232
Registered: November 2006
Senior Member
Hi Michel,

Thanks for the update.

Actually I have put a menu for the export, as shown below

# su - sysadmin

7. Full Database Export - Prod Database
8. Full Database Export - Test Database

0. EXIT

Choice :



So, in

exp_test1.sh must be like this?

echo "export ORACLE_SID=test" | su - ora10g
echo "exp system/manager full=y file=/d02/exp_tst.dmp log=/d02exp_tst.log statistics=none" | su - ora10g

exp_test.sh
su - ora10g -c exp_test1.sh

Re: shell script in Solaris [message #526200 is a reply to message #526195] Mon, 10 October 2011 02:23 Go to previous messageGo to next message
Michel Cadot
Messages: 68625
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
No, exp_test1.sh should be as I posted.
More, if your Oracle environment is correct that is oratab is filled and so on, it should be:

export ORACLE_SID=test
export ORAENV_ASK=NO
. oraenv
exp system/testpassword full=y file=/test/export.dmp log=/test/export.log


Regards
Michel

Re: shell script in Solaris [message #526321 is a reply to message #526173] Mon, 10 October 2011 09:59 Go to previous message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
dirish wrote on Sun, 09 October 2011 21:51
Hi Michel,

Thanks for the advice. Actually the client wants to go with exp/imp.


Blackswan,
The first line in red is not working

vi exp_test.sh
export ORACLE_SID=test
echo "exp system/manager full=y file=/d02/exp_tst.dmp log=/d02exp_tst.log statistics=none" | su - ora10g

Please advise


export ORACLE_SID=test

"export" is bash command & will fail when invoked by Korn shell (sh)

ORACLE_SID=test
export ORACLE_SID

above will always succeed as as not using C-Shell

Previous Topic: Create a folder with a script
Next Topic: Check if file exist using schell scripting
Goto Forum:
  


Current Time: Thu Mar 28 18:58:30 CDT 2024