korn shell: dynamic use of the EOF execution method

by Community Manager on ‎05-29-2012 02:38 PM

Question

I use in a shell script an oracle command ( RMAN ). i use the RMAN command by using the EOF execution method like below.

But the part of the channels should be dynamic - how can i create the EOF part dynamicaly ? With a temporary file ?

The input should be the number of channels and depend of the nummer i should create dynamic channels in the EOF part


NOW:
rman <<-EOF
connect catalog rman/${RMAN_CONNECT}@${RMAN_SID}
connect target  /
run {
   allocate channel dev_1 type 'SBT_TAPE';
...
...
   release channel dev_1;
}
EOF

NEW:
nr_channels=3  # so 3 channels should be exist in the EOF part

# create the dynamic part of channels
rman <<-EOF
connect catalog rman/${RMAN_CONNECT}@${RMAN_SID}
connect target  /
run {
   allocate channel dev_1 type 'SBT_TAPE';
   allocate channel dev_2 type 'SBT_TAPE';
   allocate channel dev_3 type 'SBT_TAPE';
...
...
   release channel dev_3;
   release channel dev_2;
   release channel dev_1;
}
EOF

Answer

>i use the RMAN command by using the EOF execution method

 

(These are called here documents or here docs.)

 

>how can i create the EOF part dynamic? with a temporary file?

 

Whatever is easiest and can be understood and maintained.

 

A separate file with echo and cat may be easiest.  But you can put scripts into the here doc:

rman <<-EOF
connect catalog rman/${RMAN_CONNECT}@${RMAN_SID}
connect target  /
run {

$(

for i in dev_1 dev_2 dev_3; do

   echo "   allocate channel $i type 'SBT_TAPE';"

done

)

...

$(

for i in dev_3 dev_2 dev_1; do

   echo "   release channel $i;"
done

)

}
EOF

 

But it may be easier to just create a temp file:

tmp_file=/var/tmp/tf.$$

{

cat <<-EOF1

connect catalog rman/${RMAN_CONNECT}@${RMAN_SID}
connect target  /
run {

EOF1

 

for i in dev_1 dev_2 dev_3; do

   echo "   allocate channel $i type 'SBT_TAPE';"

done

 

cat <<-EOF2

...

EOF2

 

for i in dev_3 dev_2 dev_1; do

   echo "   release channel $i;"
done


cat <<-EOF3

}

EOF3

} > $tmp_file

 

rman < $tmp_file

 

rm -f $tmp_file  # cleanup

Search
Follow Us


Twitter Stream
HP Blog
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation