user3274576
user3274576

Reputation: 27

SSH command gets hung

I have SSH command within a while loop that executes on the remote system. And I see that more the number of times it executes, higher is the chance of it getting hung. Can anyone tell me if there is any SSH configuration or option available to prevent this.

 if [ -n "${services}" ]
 then
       while [ $flag -eq 1 ]
       do
          for list in $services
          do
            outcome=`ssh $user@$remoteserver "svcs $list" | tail -1 | awk '{print $1}'`
            if [ $outcome != "online" ]
            then
                 flag=1
                 break
            else
                 flag=0
            fi
          done
       done
else
       echo "Failed to get remoteserver list" 
fi

Upvotes: 2

Views: 195

Answers (1)

fcnorman
fcnorman

Reputation: 1186

The problem is that the ssh command reads from stdin, and this drains the input to your while loop.

Change the ssh command to an ssh -n command. That is, add the "-n" option to your ssh command.

Upvotes: 1

Related Questions