Re: Problem with shell script to duplicate a database from active database

From: Mladen Gogala <gogala.mladen_at_gmail.com>
Date: Fri, 24 Jul 2020 20:25:56 -0400
Message-ID: <bb232a66-c489-784c-799e-e66ffc33967c_at_gmail.com>



When talking about scripting, nothing beats the good, old pathologically eclectic rubbish lister. The script should look something like this:

#!/usr/bin/env perl
use warnings;
use strict;
use Date::Simple;

my $ts=new Date::Simple;
my $LOG_FILE="/tmp/test_file.log";
       $LOG_FILE .= "_$ts";

my $script=qq(run {

allocate channel t1 type disk;
allocate channel t2 type disk;
allocate channel t3 type disk;
allocate channel t4 type disk;
allocate auxiliary channel a1 type disk;
allocate auxiliary channel a2 type disk;
allocate auxiliary channel a3 type disk; allocate auxiliary channel a4 type disk; duplicate target database for standby from active database nofilenamecheck
dorecover;
release channel t1;
release channel t2;
release channel t3;
release channel t4;
release channel a1;
release channel a2;
release channel a3;
release channel a4;

});

open(STDOUT,">>",$LOG_FILE) || die("Cannot open $LOG_FILE:$!\n"); open(RMAN, "|rman target sys/pwd01\_at_COMP2 auxiliary sys/pwd01\_at_COMP_DB1") || die("Cannot start rman:$!\n");

print RMAN $script;

Of course, that is a bare bones version.  One would need to add bells and whistles.. The trick here is to open the log file as the standard output, thereby making any shell redirection unnecessary. Also, utilizing Perl native "pipe to" ability makes the script quite elegant.

On 7/23/20 6:52 PM, Clay Jackson (cjackson) wrote:
>
> And definitely use ksh, not bash (since the original was ksh)
>
> *From:* oracle-l-bounce_at_freelists.org <oracle-l-bounce_at_freelists.org>
> *On Behalf Of *Ruan Linehan
> *Sent:* Thursday, July 23, 2020 3:50 PM
> *To:* sbecker6925_at_gmail.com
> *Cc:* Sayan Malakshinov <xt.and.r_at_gmail.com>; oracle-l
> <oracle-l_at_freelists.org>
> *Subject:* Re: Problem with shell script to duplicate a database from
> active database
>
> *CAUTION:*This email originated from outside of the organization. Do
> not follow guidance, click links, or open attachments unless you
> recognize the sender and know the content is safe.
>
> Hi Sandra,
>
> Can you try...
>
> << EOF >> $LOG_FILE
>
> Regards,
>
> Ruan
>
> On Thu, Jul 23, 2020 at 11:33 PM Sandra Becker <sbecker6925_at_gmail.com
> <mailto:sbecker6925_at_gmail.com>> wrote:
>
> I tried both ways and they both fail with the same errors.  I have
> been trying to research the stty error, but I don't really
> understand what I'm reading.  Shell scripting is not my strong suit.
>
> stty: standard input: Inappropriate ioctl for device
> ./sjb.ksh[11]: EOF: cannot open [No such file or directory]
> ./sjb.ksh[12]: run: not found [No such file or directory]
> ./sjb.ksh[13]: allocate: not found [No such file or directory]
> ./sjb.ksh[14]: allocate: not found [No such file or directory]
> ./sjb.ksh[15]: allocate: not found [No such file or directory]
> ./sjb.ksh[16]: allocate: not found [No such file or directory]
> ./sjb.ksh[17]: allocate: not found [No such file or directory]
> ./sjb.ksh[18]: allocate: not found [No such file or directory]
> ./sjb.ksh[19]: allocate: not found [No such file or directory]
> ./sjb.ksh[20]: allocate: not found [No such file or directory]
> ./sjb.ksh[21]: duplicate: not found [No such file or directory]
> ./sjb.ksh[22]: nofilenamecheck: not found [No such file or directory]
> ./sjb.ksh[23]: dorecover: not found [No such file or directory]
> ./sjb.ksh[25]: release: not found [No such file or directory]
> ./sjb.ksh[26]: release: not found [No such file or directory]
> ./sjb.ksh[27]: release: not found [No such file or directory]
> ./sjb.ksh[28]: release: not found [No such file or directory]
> ./sjb.ksh[29]: release: not found [No such file or directory]
> ./sjb.ksh[30]: release: not found [No such file or directory]
>
> ./sjb.ksh[31]: release: not found [No such file or directory]
> ./sjb.ksh[32]: release: not found [No such file or directory]
> ./sjb.ksh: line 32: syntax error at line 33: `}' unexpected
>
> Sandy
>
> On Thu, Jul 23, 2020 at 4:26 PM Sayan Malakshinov
> <xt.and.r_at_gmail.com <mailto:xt.and.r_at_gmail.com>> wrote:
>
> Though usually I specify output before input, ie
>
> cmd... >> $LOG_FILE <EOF
>
> ...
>
> EOF
>
> пт, 24 июл. 2020 г., 1:23 Sayan Malakshinov
> <xt.and.r_at_gmail.com <mailto:xt.and.r_at_gmail.com>>:
>
> Hi Sandra,
>
> Shouldn't "<EOF> >> $LOG_FILE" be "<EOF >> $LOG_FILE", ie
> without extra > after EOF?
>
> пт, 24 июл. 2020 г., 1:17 Sandra Becker
> <sbecker6925_at_gmail.com <mailto:sbecker6925_at_gmail.com>>:
>
> I need to create standby databases for several of our
> existing databases.  We did this last year for another
> database and I copied that lshell script, but it's
> throwing an error and I can't seem to figure out what
> is wrong with it.  This is a RHEL6 OS with Oracle
> 12.1.0.2.  It tells me there is an error on the line
> "rman target..."  It doesn't like the ">>".   These
> are large databases and my session would time out long
> before the script completed, so I need a shell script
> I can run with nohup.  I would appreciate any help you
> can provide.
>
> Error:
>
> line 11: syntax error near unexpected token `>>'
> line 11:`rman target sys/pwd01_at_COMP2 auxiliary
> sys/pwd01_at_UCOMP_DB1 <EOF> >> $LOG_FILE'
>
> Script:
>
> #!/bin/bash
> #set -x
> . /home/orcl/db_stdby_db1.ksh
>
> ts=`date +'%Y%m%d%H%M'`
> LOG_FILE='/LOGS/COMP/dumps/build_standby_COMP_DB1.log_'${ts}
> HOSTNAME=`hostname`
> STARTTIME=`date -u '+%Y_%m_%d.%H%M%S'`
> echo $STARTTIME > $LOG_FILE
>
> rman target sys/pwd01_at_COMP2 auxiliary
> sys/pwd01_at_COMP_DB1 <EOF> >> $LOG_FILE
> run {
> allocate channel t1 type disk;
> allocate channel t2 type disk;
> allocate channel t3 type disk;
> allocate channel t4 type disk;
> allocate auxiliary channel a1 type disk;
> allocate auxiliary channel a2 type disk;
> allocate auxiliary channel a3 type disk;
> allocate auxiliary channel a4 type disk;
> duplicate target database for standby from active database
> nofilenamecheck
> dorecover;
>
> release channel t1;
> release channel t2;
> release channel t3;
>
> release channel t4;
> release channel a1;
> release channel a2;
> release channel a3;
> release channel a4;
> }
> EOF
> exit
>
> -
>
> Sandy B.
>
>
>
> --
>
> Sandy B.
>

-- 
Mladen Gogala
Database Consultant
Tel: (347) 321-1217


--
http://www.freelists.org/webpage/oracle-l
Received on Sat Jul 25 2020 - 02:25:56 CEST

Original text of this message