why does ssh break a /bin/sh while loop?
Results 1 to 3 of 3

Thread: why does ssh break a /bin/sh while loop?

  1. #1
    Senior Member roswell1329's Avatar
    Join Date
    Jan 2002
    Posts
    670

    why does ssh break a /bin/sh while loop?

    I'm having trouble using ssh to execute a remote command inside a /bin/sh script. It executes just fine once, but it stops the loop execution there:

    Code:
    cat /home/guest/systems | \
    while read line
    do 
    ssh -l root $line "ls -alF /etc"
    done
    Other commands between the do and done work and won't kill the loop, but for some reason as soon as I add the ssh the loop dies. The ssh command isn't failing, so I don't think it's the return code for ssh that's killing the loop, but I don't know why it's dying. Anyone have any ideas on why this is happening and how to avoid it?
    /* You are not expected to understand this. */

  2. #2
    Just Another Geek
    Join Date
    Jul 2002
    Location
    Rotterdam, Netherlands
    Posts
    3,403
    bash, csh, ksh?

    bash# for line in `cat /home/guest/systems`; do ssh -l root $line "ls -alF /etc" ; done

    Seems to work fine


    Edit: ah.. the 'normal' bourne shell brb

    Hmm.. logic error? Pipe being connected to ssh instead of while?

    The bash line above should work in sh too..
    Oliver's Law:
    Experience is something you don't get until just after you need it.

  3. #3
    Senior Member roswell1329's Avatar
    Join Date
    Jan 2002
    Posts
    670
    Thanks, SirDice. That worked. I'm thinking it was the pipe in combination with the ssh in my loop that killed it.
    /* You are not expected to understand this. */

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •