1755458 Members
3424 Online
108833 Solutions
New Discussion юеВ

remsh in a loop

 
SOLVED
Go to solution
Sundar_7
Honored Contributor

remsh in a loop

Folks,

Long time :-). I would like to think myself as a reasonably skilled scripter but this one baffled me. I just could not figure out what am I missing here.

I have this file serverlist that lists all the servers with some comments in between

# grep -v "^#" serverlist | wc -l
109
#

All I am trying to do is to execute a simple command via remsh to all of the machines from a node that has .rhosts entries

# grep -v "^#" serverlist | awk '{print $1}' | xargs -n1 | while read SERVERNAME
> do
> remsh $SERVERNAME "echo Hey"
> done
Hey
Hey
#

Why on the god's green earth the loop will exit just after two iteration? Even if there is something wrong, I should get an error message from remsh

# grep -v "^#" serverlist | awk '{print $1}' | xargs -n1 | while read SERVERNAME
> do
> echo $SERVERNAME
> done | wc -l
109
#

Am I missing something very obvious?

- Sundar.
Learn What to do ,How to do and more importantly When to do ?
15 REPLIES 15
harry d brown jr
Honored Contributor

Re: remsh in a loop

can you try:

xargs -i echo remsh {} "some command"

live free or die
harry d brown jr
Live Free or Die
Sundar_7
Honored Contributor

Re: remsh in a loop

Yes, Harry - that seem to work. But what is wrong with my "for" loop ? - I have successfully executed the similar "for" loops in the past.
Learn What to do ,How to do and more importantly When to do ?
harry d brown jr
Honored Contributor

Re: remsh in a loop

Check your "serverlist" file for funky characters.

check "which grep" you are using.
check "which awk" you are using.
check "which xargs" you are using.
check "chich remsh" you are using.

Also, try replacing the remsh $SERVERNAME line with this:

host ${SERVERNAME}

just to make sure you have "good" server names.

live free or die
harry d brown jr
Live Free or Die
Geoff Wild
Honored Contributor

Re: remsh in a loop

What if you try a for instead of while?

for SERVER in `grep -v "^#" serverlist | awk '{print $1}' | xargs -n1 `
do
echo "$SERVER"
remsh $SERVER "echo hey"
done

Can you post your serverlist file?

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Sundar_7
Honored Contributor

Re: remsh in a loop

for loop works just fine. I know how to work around. So that is not what I am looking for.

Harry - if there are funky names, how do you think xargs -i remsh {} is working ?

grep -v "^#" serverlist | awk '{print $1}' | xargs -i remsh {} date

this work. Doesnt it confirm the grep, awk ,xargs and the serverlist are just fine ?
Learn What to do ,How to do and more importantly When to do ?
harry d brown jr
Honored Contributor

Re: remsh in a loop

how about changing
remsh $SERVERNAME "echo Hey"
to
remsh $SERVERNAME /usr/bin/echo Hey

live free or die
harry d brown jr
Live Free or Die
Sundar_7
Honored Contributor

Re: remsh in a loop

Again, if /usr/bin/echo must be used instead of echo, how does the remshell with in the "for" loop works with just echo ?
Learn What to do ,How to do and more importantly When to do ?
Biswajit Tripathy
Honored Contributor

Re: remsh in a loop

Sunder,

Just a wild guess :-)

Does your serverlist file have a comment which
starts in the middle of a line? In other words, do
you have a '#' char at some place other than
first column?

- Biswajit
:-)
harry d brown jr
Honored Contributor

Re: remsh in a loop

because echo locally is one thing. Specifying the absolute path on the remote host is another.

Can you post your "input" file "serverlist" ??

thanks,


live free or die
harry d brown jr
Live Free or Die