Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need help with KSH script << EOF 3

Status
Not open for further replies.

gerardus

Technical User
Feb 6, 2002
13
0
0
NL
I made this script:

sid=test
cat=tcatalog
targetww=`cat /xxx/xxx`
catww=`cat /xxx/xxx`
rman target $targetww@$test catalog $catww@$cat

This connect to the target and catalog rman databases. Next you see is the rman prompt so you can give rman commands. The problem is 'you can see the passwords in de 'ps' list'.

So I made this:

sid=test
cat=tcatalog
targetww=`cat /xxx/xxx`
catww=`cat /xxx/xxx`
rman target << EOF
$targetww@$test
catalog $catww@$cat
EOF

But this does not work. I don't get de rman prompt. Please help.


 
I don't know rman but it looks like it is reading from the terminal directly rather than from stdin. expect or similar may help.
 
SJM, thanks. But I think it is reading from stdin. The rman command starts, there is a prompt, it is connecting aan 2 databases - and that is the moment I want to have the prompt, so I can give some other commands. The problem is rman is closed immediately.
 
Looks like you have a space between '<<' and 'EOF'. Remove the space and see if that helps.

Regards,
Chuck
 
An excellent spot, Chuck, have a star even if it's not the problem!

The internet - allowing those who don't know what they're talking about to have their say.
 
The <<EOF did not work. May be my question was not clear. Again:

In this case I can give RMAN commands, but de passwords are readable in de PS list:

rman target xxx/xxxx@xxxx connect catalog xxx/xxxxx@xxxxx
connected to target database: xxx (DBID=xxxxx)
connected to recovery catalog database
RMAN> (here I can give RMAN commands)



In this case I cannot give RMAN commands because RMAN is closing directly:

rman <<EOF
connect target xxx/xxxx@xxxx
connect catalog xxx/xxxxx@xxxxx
EOF
........
RMAN> connected to target database: xxxx (DBID=xxxx)
RMAN> connected to recovery catalog database

Recovery Manager complete.




 
Your talking about the re-assignment of stdin from a parent process to a child process within a script.

I dont think this is possible.
If someone does know a way to do it I'd love to know. :)

In this case your best bet is to use your script arguments as the RMAN command to execute.

RMAN_CMD="$*"
sid=test
cat=tcatalog
targetww=`cat /xxx/xxx`
catww=`cat /xxx/xxx`
rman target << EOF
$targetww@$test
catalog $catww@$cat
$RMAN_CMD
EOF

Then use the your script with the required RMAN command as an argument.

my_rman_script my rman command

Or something similar.

Adjust to measure. :)

____________________
Sometimes it pays to stay in bed on Monday, rather than spending the rest of the week debuging Mondays code.
 
ok, too bad... Thanks for the help. I'll try your suggestion.
 
You can do some dirty tricks with coprocesses (ksh or bash >= 4.0) or pipes. Here an example for bash 3.2
Code:
#!/bin/bash
rmanpipe=/tmp/rman.pipe.$$
mkfifo $rmanpipe
trap "rm -f $rmanpipe" EXIT
rman <$rmanpipe &
exec 1>&-
exec 1>$rmanpipe
echo "connect target $targetww@$test" >$rmanpipe
echo "connect catalog $catww@$cat" >$rmanpipe
while read user_input; do
   echo $user_input >$rmanpipe
   if [ "$user_input" = "exit" ]; then
      break
   fi
done
 
Hi Stefanhi,

This is great. I use the ksh, and I changed one line: mknod $rmanpipe p. Thanks a lot!

regards,

Gerard
 
Glad to hear this, but be careful, the script is just an example. If the user exits using exit[red];[/red] the script will hang - some work there if you wish to use this in a production environment. Also trap for abnormal exits too (0 2 3 9 15).
In ksh you could use coprocesses: rman |& and communicate using print -p and avoid creating pipes manually.
 
Gerard - surely Stefan deserves a star for his efforts?

The internet - allowing those who don't know what they're talking about to have their say.
 
Yes of course, I didn't know of a star... Now I see.
Thanks for the tip.

Stefan you have your star!
 
Oops - I seem to have acquired a star instead - passed to Stefan!

The internet - allowing those who don't know what they're talking about to have their say.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top