miércoles, 27 de mayo de 2009

Oracle Shell Scripting Unix

UNIX and Linux (Method 1)The previous methods works equally well in UNIX and Linux environments. For example, save the following

script in a file called "/u01/emp.sql".

CONNECT scott/tiger
SPOOL /u01/emp.lst
SET LINESIZE 100
SET PAGESIZE 50
SELECT *
FROM emp;
SPOOL OFF
EXIT;

Next, create a shell script called "/u01/get_emp.ksh" containing the following lines.
#!/bin/ksh

sqlplus /nolog @/u01/emp.sql

The following command makes the file executable for the file owner.

chmod u+x /u01/get_emp.ksh

The resulting shell script can be run manually from the command line, or scheduled using CRON.For RMAN, place the following

RMAN commands in a file called "/u01/cmdfile.txt".


RUN {
ALLOCATE CHANNEL ch1 TYPE
DISK FORMAT '/u01/backup/DB10G/%d_DB_%u_%s_%p';
BACKUP DATABASE PLUS ARCHIVELOG;
RELEASE CHANNEL ch1;
}
EXIT;

Next create a batch file called "/u01/backup.ksh" containing the following lines.

#!/bin/ksh

rman target=/ @/u01/cmdfile.txt

This command can include a catalog= entry if a recovery catalog is used. Once again, resulting shell script must be made executable using the following command.

chmod u+x /u01/backup.ksh


UNIX and Linux (Method 2)

UNIX and Linux environments also allow the SQL*Plus and RMAN commands to be piped directly from the command line. For example, save the following commands in a file called "/u01/get_emp.ksh".

#!/bin/ksh

sqlplus /nolog << EOF

CONNECT scott/tiger
SPOOL /u01/emp.lst
SET LINESIZE 100
SET PAGESIZE 50
SELECT *
FROM emp;
SPOOL OFF
EXIT;
EOF

chmod u+x /u01/get_emp.ksh

#!/bin/ksh

rman target=/ << EOF

RUN {
ALLOCATE CHANNEL ch1 TYPE
DISK FORMAT '/u01/backup/DB10G/%d_DB_%u_%s_%p';
BACKUP DATABASE PLUS ARCHIVELOG;
RELEASE CHANNEL ch1;
}
EXIT;
EOF

chmod u+x /u01/backup.ksh