[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: how to check the server can be connected or not



On 03/02/12 15:05, Jon Dowland wrote:
On 03/02/12 09:55, lina wrote:
On Friday 03,February,2012 05:32 PM, Jon Dowland wrote:

while true; do
ssh server && break
done


Thanks for both of you,

the two ways once ssh server,
it stayed in server and won't come back and proceed the rest.

I don't fully understand your follow-up, but to explain my solution: it
will loop as long as the ssh process returns an error code. So if the
ssh session connects successfully, upon ending the session, it will
return a success code and the loop will stop.

If I understand correctly, the OP was just using the SSH session to check for connectivity, they don't acually want to run a session at that point.

If so, the following may work:

while true; do
ssh server : 2>/dev/null && break
done

This will attempt to run the dummy command ":" on "server" (throwing away any error messages) until successful. It might be an idea to put a "sleep 10" or something in there too.
--
Dom


Reply to: