Operating System - HP-UX
1834247 Members
2350 Online
110066 Solutions
New Discussion

Script help (while, pipe and remsh"

 
SOLVED
Go to solution
Kellogg Unix Team
Trusted Contributor

Script help (while, pipe and remsh"

Gurus,

I need some help with the following script. I have a file "a" with the following syntax -
hostA fileA1 fileA2
hostB fileB1 fileB2
hostC fileC1 fileC2
(... and so on)

I want to read this file (one line at a time)and check the existence of files in respective hosts. The script, I am using is -
#!/bin/sh
cat a|while read x y z
do
remsh $a "ll $y $z"
done

The problem is that the script is reading just first line of the file "a" and never goes further. If I replace remsh command with echo (say, echo $x, $y, $z), all line of file "a" are read.

What do I need to make the script work? I am puzzled because echo works but remsh stops after reading first line. (And yes, I do have remsh capability as that user on all hosts listed in file "a")

Thanks in advance
...Manjeet
work is fun ! (my manager is standing behind me!!)
8 REPLIES 8
harry d brown jr
Honored Contributor

Re: Script help (while, pipe and remsh"


WHAT is $a set too??

live free or die
harry
Live Free or Die
Hai Nguyen_1
Honored Contributor
Solution

Re: Script help (while, pipe and remsh"

Manjeet,


Replace "remsh $a" with "remsh $a -n".

Hai
harry d brown jr
Honored Contributor

Re: Script help (while, pipe and remsh"

remsh $x -n ll $y $z"


live free or die
harry
Live Free or Die
John Poff
Honored Contributor

Re: Script help (while, pipe and remsh"

Hi Manjeet,

It looks like you are reading the contents of file 'a' into variables x, y, and z. Shouldn't your 'remsh' line read:

remsh $x "ll $y $z"


JP
Ray Brewer
Valued Contributor

Re: Script help (while, pipe and remsh"

I ran into this a while back and the "-n" is required when running remsh in a loop. The -n option redirects standard input to remsh from /dev/null

Ray
Ray Brewer
Valued Contributor

Re: Script help (while, pipe and remsh"

To expand on my previous reply, here is what the man page on remsh says about the "-n" option and why it is required

By default, remsh reads its standard input and sends it to the remote command because remsh has no way to determine whether the remote command requires input. The -n option redirects standard input to remsh from /dev/null. This is useful when running a shell script containing a remsh command, since otherwise remsh may use input not intended for it. The -n option is also useful when running remsh in the background from a job control shell, /usr/bin/csh or /usr/bin/ksh. Otherwise, remsh stops and waits for input from the terminal keyboard for the remote command. /usr/bin/sh automatically redirects its input from /dev/null when jobs are run in the background.
Kellogg Unix Team
Trusted Contributor

Re: Script help (while, pipe and remsh"

Thanks to all for correctly pointing out correct usage of remsh (remsh -n). That did the trick! And thanks for pointing out the typo ! Yes it was "remsh $x "ll $y $z" and not "remsh $a ..." as put in my original post. (I wish there is edit button to edit my first post !!)

Thanks again!
work is fun ! (my manager is standing behind me!!)
harry d brown jr
Honored Contributor

Re: Script help (while, pipe and remsh"

Ignore that last quote in my past post. cut and paste this:


#!/bin/sh
cat a|while read x y z
do
remsh $x -n "ll $y $z"
done

live free or die
harry
Live Free or Die