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 < $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?