Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 05-18-2007, 11:16 AM   #1
LQ Newbie
Registered: May 2007
Posts: 2

Rep: Reputation: 0
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.
Old 05-18-2007, 11:49 AM   #2
Senior Member
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
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.

Last edited by anomie; 05-18-2007 at 11:50 AM.
Old 05-18-2007, 02:42 PM   #3
LQ Newbie
Registered: May 2007
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks, that worked perfectly!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
help with Bash script (test) Benanzo Linux - Software 1 04-09-2007 04:18 AM
bash script problems: scp/ssh from the node of a cluster to the other server frankie_DJ Programming 2 01-27-2007 07:29 PM
bash script: ssh to server and reply to any questions cambie Programming 2 09-28-2006 10:44 AM
bash script 'test' question linmix Programming 5 11-29-2005 12:49 PM
benchmark test bash script PTBmilo Programming 3 02-14-2003 05:37 PM

All times are GMT -5. The time now is 08:43 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration