LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-24-2015, 01:09 PM   #1
Mike_Brown
Member
 
Registered: May 2015
Posts: 37

Rep: Reputation: Disabled
how to set a time limit of ssh


I have a hostlist and there are several hosts. I want to use ssh to connect to them. I want to see whether the host is available or not by the time length of ssh takes. If it take long than 5s (which means it is not available). Then stop it, and ssh to next host. Once a host is available, then output the name of host. I previously use nmap, but the IT security told it is not allowed to install it on the desktop on campus.
Code:
host_list="/home/campus27/zwang10/Desktop/cluster/program/hostlist"
HOSTS=`cat $host_list`
for line in $HOSTS
do 
timeout -5s `ssh $line`
done
The above script is all I can do.
 
Old 05-24-2015, 09:46 PM   #2
wpeckham
Senior Member
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, Fedora, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, Vsido, tinycore, Q4OS
Posts: 2,224

Rep: Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893
ssh may be the hard way

Just need to point out that you only REALLY need to check if port 22 is accepting connections at that address. For that your could use nc (netcat) or even telnet. There is also a bash trick that uses a virtual device file for shell network activity. Most likely the telnet thing is easiest. I seem to remember solving a problem somewhat like that in perl once, which may apply here.

There are undoubtedly other and arguably better ways. The optimal choice for you may depend upon the software set that is acceptable in your environment. I cannot determine that from your initial post.

The important point is: do not limit yourself to using ssh. Find another tool, one that is readily available to you, that will help you solve that problem.

Last edited by wpeckham; 05-24-2015 at 09:47 PM.
 
Old 05-25-2015, 05:19 AM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,702

Rep: Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270
Quote:
Originally Posted by Mike_Brown View Post
I have a hostlist and there are several hosts. I want to use ssh to connect to them. I want to see whether the host is available or not by the time length of ssh takes. If it take long than 5s (which means it is not available). Then stop it, and ssh to next host. Once a host is available, then output the name of host. I previously use nmap, but the IT security told it is not allowed to install it on the desktop on campus.
Code:
host_list="/home/campus27/zwang10/Desktop/cluster/program/hostlist"
HOSTS=`cat $host_list`
for line in $HOSTS
do 
timeout -5s `ssh $line`
done
The above script is all I can do.
Instead of making a session with ssh, why not use "ssh $line echo 'Ok'". That way you will get back an "Ok" message if things are working (and exit status 0) --- and if your timeout occurs, things are NOT working (exit status 124).

Last edited by jpollard; 05-25-2015 at 05:26 AM.
 
Old 05-25-2015, 07:17 AM   #4
wpeckham
Senior Member
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, Fedora, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, Vsido, tinycore, Q4OS
Posts: 2,224

Rep: Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893
Curious

I see you marked the thread solved. Can you mention what you used in your solution?
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Is there a set limit to how many drives fsck will check in parallel at one time? rjo98 Linux - Server 8 01-30-2015 09:33 AM
NTP: time correction of 1879 seconds exceeds sanity limit (1000); set clock manually LittleMaster Linux - Newbie 1 07-15-2013 05:02 AM
Set time limit for a service managed by xinetd? chu_bun Linux - Server 5 08-14-2010 11:59 AM
set time limit on allowed user in iptables? luap Linux - Networking 5 03-04-2003 10:55 PM
set daily time limit for being logged into machine? JustinHoMi Linux - General 1 10-15-2001 12:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:42 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration