Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

korn shell: dynamic use of the EOF execution method

SOLVED
Go to solution
Highlighted
support_billa
Valued Contributor

korn shell: dynamic use of the EOF execution method

Hello,

I have following issue :

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 by dynamic. how can i create the EOF part dynamic ? 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

regards

3 REPLIES
Dennis Handly
Acclaimed Contributor
Solution

Re: korn shell: dynamic use of here docs

>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

support_billa
Valued Contributor

Re: korn shell: dynamic use of here docs

hello,

 

i prefer option 1, but option 2 is also an alternative.

 

here my solution :

 

NR_CHANNELS=3  # define number of channels, starts with "0"
i=0
(( ii = NR_CHANNELS - 1 ))

rman <<-EOF
..
#  allocate channel : dynamic part
#  allocate channel dev_0 type 'SBT_TAPE';
$( 
while [ ${i} -lt ${NR_CHANNELS} ]; do
  echo "allocate channel dev_${i} type 'SBT_TAPE';"
  (( i += 1 ))
done
)
#  release channel : dynamic part
#  release channel dev_0;
$( 
until [ ${ii} -lt 0 ]; do
  echo "release channel dev_${ii};"
  (( ii -= 1 ))
done
)
}
EOF

 

last question :

 

is there a difference between :

 

cat <<-EOF

 

and

 

cat <<EOF  ( without "-" )

 

regards

Dennis Handly
Acclaimed Contributor

Re: korn shell: dynamic use of here docs

>is there a difference between: cat <<-EOF

 

As documented, that "-" causes all leading tabs to be removed