FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > CentOS > CentOS

 
 
LinkBack Thread Tools
 
Old 02-01-2012, 08:46 PM
Alexander Dalloz
 
Default Bash scripting - Remotely ran commands break while loop

Am 01.02.2012 22:07, schrieb Peter Blajev:
> I have two CentOS5 systems server1 and server2. There is user peter on
> server1 who can ssh to server2 using public ssh keys and no password is
> needed.
>
> What I noticed is that running remote ssh commands in bash script breaks
> while loops.
>
> ======
> #!/bin/sh
> for i in server2 server2; do
> echo "--> Start"
> ssh peter@$i ls
> echo "--> END"
> done
>
> echo " server2
> server2" |
> while read confLine; do
> echo "--> $confLine"
> ssh peter@$confLine ls
> echo "--> END $confLine"
> done
> ====
>
> The "for" loop in the script above will run twice but the "while" loop
> below it will run only once.
>
> This is very simple to test and I've tried it on different systems
> including CentOS6 and OpenSolaris with the same result.
>
> Any idea what would cause the ssh command to break the while loop?
>
> Thanks
> Peter

That has simply nothing to do with SSH. Compare following:

echo "foo bar" | while read LINE; do echo $LINE; done

and

echo -e "foo
bar" | while read $LINE; do echo $LINE; done

Alexander


_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 02-01-2012, 09:04 PM
Les Mikesell
 
Default Bash scripting - Remotely ran commands break while loop

On Wed, Feb 1, 2012 at 3:46 PM, Alexander Dalloz <ad+lists@uni-x.org> wrote:
>
> That has simply nothing to do with SSH. Compare following:
>
> echo "foo bar" | while read LINE; do echo $LINE; done
>
> and
>
> echo -e "foo
bar" | while read $LINE; do echo $LINE; done

No, (a) that read $LINE should be read LINE and (b) echo "foo
bar" | something
should preserve the quoted newline.
Ssh does seem to be consuming stuff from the inherited piped stdin
even though it isn't obvious what it does with it in a non-interactive
scenario. But anything that reads stdin inside the loop would cause
that (throw a 'cat >dev/null' in...).

--
Les Mikesell
lesmikesell@gmail.com
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 

Thread Tools




All times are GMT. The time now is 03:15 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org