The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > OS Specific Forums > SUN Solaris
Google UNIX.COM


SUN Solaris The Solaris Operating System, usually known simply as Solaris, is a free Unix-based operating system introduced by Sun Microsystems .

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Please help on IF statements. filthymonk Shell Programming and Scripting 4 07-18-2007 02:59 AM
Else in If Statements chapmana UNIX for Dummies Questions & Answers 8 11-30-2006 04:07 AM
Conditional Statements cstovall Shell Programming and Scripting 1 05-15-2005 02:58 PM
or statements? Blip Shell Programming and Scripting 1 01-19-2004 12:08 PM
if statements lilas UNIX for Dummies Questions & Answers 2 03-22-2001 07:49 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-02-2008
Registered User
 

Join Date: Aug 2007
Location: Australia
Posts: 107
Stumble this Post!
Automate SQL statements

Hello,
On unix side, I have written below script for taking oracle db backup. But when I tried to execute it - i could not execute the sql statements from unix.
Please suggest
------------------------
$ more bkp.sh
#!/bin/ksh
# make sure database is shutdown cleanly
sqlplus '/ as sysdba' <<eof
{
shutdown immediate;
startup force dba pfile=$ORACLE_HOME/dbs/init.ora;
shutdown immediate;
}
exit;
eof
#Mount the database and start backup
run {
startup mount pfile=$ORACLE_HOME/dbs/init.ora;
}
# Backup datafile, controlfile and archivelogs
rman target=/ << EOF
RUN {
allocate channel ch1 type
disk format '/u00/oradata/backup/%d_DB_%u_%s_%p_%t';
backup database include current controlfile
tag = '1_daily_backup';
release channel ch1;
}
EXIT;
EOF
# Open the database
run {
alter database open;
}
# Archive all logfiles including current
run {
sql 'ALTER SYSTEM ARCHIVE LOG CURRENT';
}
# Backup outdated archlogs and delete them
rman target=/ << EOF
RUN {
allocate channel ch1 type
disk format '/u00/oradata/backup/%d_DB_%u_%s_%p_%t';
backup archivelog
until time 'Sysdate-2' all
delete input;
release channel ch1;
}
EXIT;
EOF
# Backup remaining archlogs
rman target=/ << EOF
RUN {
allocate channel ch1 type
disk format '/u00/oradata/backup/%d_DB_%u_%s_%p_%t';
backup archivelog all;
release channel ch1;

}
EXIT;
EOF
------------------------

Thank you!
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-02-2008
Registered User
 

Join Date: Dec 2007
Posts: 255
Stumble this Post!
what do you mean could not execute the sql statements. what errors did you receive?

also, please use the code tags(the # icon) around your code.
Reply With Quote
  #3 (permalink)  
Old 01-02-2008
Registered User
 

Join Date: Aug 2007
Location: Australia
Posts: 107
Stumble this Post!
Ok - I get what was wrong in the script. I was running sql commands within run { } , i have modified and kept all sql statements within sqlplus '/ as sysdba' <<eof
{ ... } and all the rman related commands under rman target=/ << EOF
RUN { ... }

The script looks to be working fine now - Thanks. Except one below error in below piece:
sqlplus '/ as sysdba' <<eof
{
shutdown immediate;
startup mount;
}
exit;
eof

Error is:
SQL> SP2-0042: unknown command "}" - rest of line ignored.
Reply With Quote
  #4 (permalink)  
Old 01-02-2008
Registered User
 

Join Date: Aug 2007
Location: Australia
Posts: 107
Stumble this Post!
Thanks - The problem is resolved now and I learn that in unix script style - SQL commands dont require parenthesis and will run as below:
sqlplus '/ as sysdba' <<eof
alter database open;
ALTER SYSTEM ARCHIVE LOG CURRENT;
exit;
eof

Thank you for the hints.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:45 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0