Need some shell scripting help

I usually script in perl, but I am now needing some sh, and am getting my ass kicked.

I have a file with MANY lines in the following format:

<servername> <username>

I want to use that information to ssh to the server and remotely execute a command, for example ssh user@server ls

The following is what I have:


#!/bin/sh
       
while read line; do
  line=`echo $line|tr -d "\012"`
  part1=`echo $line | awk '{print $1}'`
  part2=`echo $line | awk '{print $2}'`
  echo "$part1"
  echo "$part2"
  ssh $part2@$part1 ls

  done &lt; $1

What happens is that the script executes the ssh command the first time, returns the result, then exits and the whole script dies. It never continues to loop.

If I comment out the ssh and just print out the username and servername, it loops correctly.

What am I missing/doing wrong?

figured it out, for future reference, ssh needs a -n flag to ignore stdin

since I am passing the $1 into the while loop as stdin, ssh was barfing

Not sure. Looks fine and works for me and I can’t think of any characters that SSH would return that would break a loop, but I could be missing something. Are you invoking the script from a normal user or through some other process?

Edit: good catch.

I guess you could debug it by using echo before the ssh command

already figured it out, see post #2. Thanks for the links though.