LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices



Reply
 
Search this Thread
Old 05-18-2007, 11:16 AM   #1
DanHulton
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.

Psuedo-code:

Code:
Loop
  Status message: Waiting for server to finish startup...
Until SSH is available.
 
Old 05-18-2007, 11:49 AM   #2
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora, Lubuntu, FreeBSD
Posts: 3,930
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:
Code:
$ while true ; do nc -z 10.0.50.50 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
DanHulton
LQ Newbie
 
Registered: May 2007
Posts: 2

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


Reply


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 12:27 AM.

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