- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- korn shell: dynamic use of the EOF execution metho...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-24-2012 05:24 AM
тАО05-24-2012 05:24 AM
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
Solved! Go to Solution.
- Tags:
- here doc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-24-2012 01:03 PM
тАО05-24-2012 01:03 PM
Solution>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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-29-2012 04:23 AM
тАО05-29-2012 04:23 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-29-2012 06:28 AM
тАО05-29-2012 06:28 AM
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