Operating System - HP-UX
1833852 Members
2321 Online
110063 Solutions
New Discussion

"while read" loop and RCMDs

 
SOLVED
Go to solution
Jack Werner
Frequent Advisor

"while read" loop and RCMDs

I am testing a .ksh script that will parse one of our oracle .cfg files and extract its host and dbatools variables. I also pass the name of the file to be "pushed" to each Oracle host. The extracted vars are processed by a "while read ... do" loop. Within the do loop... I coded..
remsh $host chmod 600 $dbatools/backup/$1
rcp -rp $1 $host:$dbatools/backup
I also echo each command before execution for logging purposes. When I comment off the r-commands, echo shows all hosts & dbatools extracted. When I uncomment the r-commands, the while exits after processing the first host & dbatool extracted.
Help
i'm retired
5 REPLIES 5
A. Clay Stephenson
Acclaimed Contributor

Re: "while read" loop and RCMDs

Hi Jack,


remsh $host chmod 600 $dbatools/backup/$1
rcp -rp $1 $host:$dbatools/backup

The first thing that occurs to me is that there is no $dbatools/backup directory. Since remsh reports nothing about the exit status of the process, you would know nothing.
Also, it appears that the two commands are reversed, it seems you are try to do a chmod on the files before they have been rcp'ed.
I would also for safety's sdake add a change
rcp -rp $1 $host:$dbatools/backup
to
rcp -rp $1 $host:$dbatools/backup/

Regards, Clay
If it ain't broke, I can fix that.
Jack Werner
Frequent Advisor

Re: "while read" loop and RCMDs

Clay,

Thanks for the reply. The reason I do the chmod first, is because the files are read-only.(ie 444), and they must be RW to be overwritten. BTW I am logged in as "oracle" while running this script, and "oracle" is the owner of all of the files being pushed to all the oracle hosts.
i'm retired
A. Clay Stephenson
Acclaimed Contributor

Re: "while read" loop and RCMDs

Okay Jack,

Thought Number 2, (I assume you have done this outside your script but I have to ask so that I know we are not fighting hosts.equiv and .rhosts problems) Have you executed both commands as oracle. Unless you have stderr redirected I'm surprised that you don't see any error messages.

Clay
If it ain't broke, I can fix that.
Jack Werner
Frequent Advisor

Re: "while read" loop and RCMDs

Its as if something causes the "while read do" loop to exit after processing the first line read. The 'somthing' is closely related to the remsh and rcp commands, since echo statements can show the entire list that while read.
i'm retired
Alan Riggs
Honored Contributor
Solution

Re: "while read" loop and RCMDs

You are running into a problem with stdin. Remsh will by default read from stdin, which clears all remaining entries from your while loop. Using the -n flag to remsh will correct this.