-   Linux - General (
-   -   Bash script to test if I can SSH to a server? (

DanHulton 05-18-2007 11:16 AM

Bash script to test if I can SSH to a server?
I have an environment when I lauch three virtual machines, then mount them via sshfs. I want to write a bash script to launch all three machines and mount them automatically.

My original plan was to use ping to identify when the servers were up, but they resolve via ping almost instantly. SSH login is only available later.

The vast majority of the script is functioning, the only part I'm missing is a section to test if I can SSH into the machine yet or not.



  Status message: Waiting for server to finish startup...
Until SSH is available.

anomie 05-18-2007 11:49 AM

Check if your netcat implementation supports the -z (list only, don't send data) option. If not, never mind. If so, you can use something like the following:

$ while true ; do nc -z 22 && break; echo 'Waiting for remote sshd...'; done
edit: You can add a sleep in there if needed.

DanHulton 05-18-2007 02:42 PM

Thanks, that worked perfectly!

All times are GMT -5. The time now is 03:35 PM.