RE: ssh breaks while loop

2006-08-14 Thread Kenneth Nellis
FWIW, I see the same behavior, but not just Cygwin, but also on 
a Red Hat Linux installation, so I guess it's more of a bash/ssh 
issue than one with Cygwin. A workaround that works for me is the 
following:

for host in $(hostlist)
do
ssh $host ls -al .profile
done


-Original Message-
From: CB [mailto:[EMAIL PROTECTED] 
Sent: Friday, August 04, 2006 10:01 AM
To: cygwin@cygwin.com
Subject: ssh breaks while loop


If file hostlist contains:
hosta
hostb
hostc
 
then execute this shell script:
while read host
do
ssh $host ls -al .profile
done  hostlist
 
the while loop executes one time and quits.
 
But,
while read host
do
echo $host
done  hostlist
 
executes 3 times.
 
Am I missing something or is this a bug?


--
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple
Problem reports:   http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ:   http://cygwin.com/faq/



Re: ssh breaks while loop

2006-08-14 Thread Ehud Karni
On Mon, 14 Aug 2006 09:54:21 -0400, Kenneth Nellis wrote:

 FWIW, I see the same behavior, but not just Cygwin, but also on
 a Red Hat Linux installation, so I guess it's more of a bash/ssh
 issue than one with Cygwin.

There are 2 issues here, One is ssh's, the other is with sh/bash.
None is Cygwin specific, i.e. it is OFFTOPIC.

On Friday, August 04, 2006 10:01 AM, BC wrote:
BC If file hostlist contains:
BC hosta
BC hostb
BC hostc
BC
BC then execute this shell script:
BC while read host
BC do
BC ssh $host ls -al .profile
BC done  hostlist
BC
BC the while loop executes one time and quits.

The problem is that `ssh' read stdin. To overcome this change it to:
ssh $host ls -al .profile  /dev/null

A second possible problem is that ssh may exit with error, the
solution is to add  set +e  (in separate line) before the ssh line.

Ehud.


--
 Ehud Karni   Tel: +972-3-7966-561  /\
 Mivtach - Simon  Fax: +972-3-7966-667  \ /  ASCII Ribbon Campaign
 Insurance agencies   (USA) voice mail and   X   Against   HTML   Mail
 http://www.mvs.co.il  FAX:  1-815-5509341  / \
 GnuPG: 98EA398D http://www.keyserver.net/Better Safe Than Sorry

--
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple
Problem reports:   http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ:   http://cygwin.com/faq/



Re: ssh breaks while loop

2006-08-04 Thread Larry Hall (Cygwin)

CB wrote:

If file hostlist contains:
hosta
hostb
hostc
 
then execute this shell script:

while read host
do
ssh $host ls -al .profile
done  hostlist
 
the while loop executes one time and quits.
 
But,

while read host
do
echo $host
done  hostlist
 
executes 3 times.
 
Am I missing something or is this a bug?



This isn't Cygwin-specific so it's off-topic for this list.

--
Larry Hall  http://www.rfk.com
RFK Partners, Inc.  (508) 893-9779 - RFK Office
216 Dalton Rd.  (508) 893-9889 - FAX
Holliston, MA 01746

--
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple
Problem reports:   http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ:   http://cygwin.com/faq/



Re: ssh breaks while loop

2006-08-04 Thread Igor Peshansky
On Fri, 4 Aug 2006, CB wrote:

 If file hostlist contains:
 hosta
 hostb
 hostc

 then execute this shell script:
 while read host
 do
 ssh $host ls -al .profile
 done  hostlist

 the while loop executes one time and quits.

 But,
 while read host
 do
 echo $host
 done  hostlist

 executes 3 times.

 Am I missing something or is this a bug?

WJFFM.  There are many things that can be different in our environments.
Are you sure you're reading the hosts separately?  What's IFS set to?
Try prepending something to $host in your second loop, e.g., echo Host:
$host and see if you get them echoed one host at a time, or all three at
once.  You may also insert echo before the ssh in the first loop and see
if you get 3 echoes.  Also, is set -e in effect?  If it is, the loop may
be quitting if the first ssh returns false.
Igor
-- 
http://cs.nyu.edu/~pechtcha/
  |\  _,,,---,,_[EMAIL PROTECTED] | [EMAIL PROTECTED]
ZZZzz /,`.-'`'-.  ;-;;,_Igor Peshansky, Ph.D. (name changed!)
 |,4-  ) )-,_. ,\ (  `'-'   old name: Igor Pechtchanski
'---''(_/--'  `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

Las! je suis sot... -Mais non, tu ne l'es pas, puisque tu t'en rends compte.
But no -- you are no fool; you call yourself a fool, there's proof enough in
that! -- Rostand, Cyrano de Bergerac

--
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple
Problem reports:   http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ:   http://cygwin.com/faq/