waiting for ssh response for seconds


 
Thread Tools Search this Thread
Special Forums UNIX and Linux Applications waiting for ssh response for seconds
# 1  
Old 12-09-2008
waiting for ssh response for seconds

Hi All,


I have to make an alert that'll wait for ssh response from the server for certain seconds, if no response is there in between it'll raise an alarm.

Havn't found any option for this yet, pls. help if anyone knows abt this. Any suggestion is welcome. Smilie



Best Regards,
VG
# 2  
Old 12-09-2008
Not sure if there is an SSH option for that, however, there is the 'netcat' utility, which you can connect to a certain post, and you can set a timeout.

For instance:

Code:
netcat -z -w <timeout in seconds> <host> <port>

So to check to see if ssh will respond withing 5 seconds, so the following:

Code:
netcat -z -w 5 host.example.com 22 || /bin/some_custom_alert

The '-z' option will make it disconnect as soon as it makes a connection to the port, and of course '-w' is to set the timeout in seconds.

If it does not connect, it will return a non-zero exit status, in which case, you would know to raise your alarm.

Hope this helps...
# 3  
Old 12-10-2008
nc solution above is good, if you want to consider ssh command, the option is
Quote:
-oConnectTimeout
, but to be sure check the man pages for your OS.
# 4  
Old 03-03-2009
Thanks for the solution . It works gr8. Smilie


Quote:
Originally Posted by Gee-Money
Not sure if there is an SSH option for that, however, there is the 'netcat' utility, which you can connect to a certain post, and you can set a timeout.

For instance:

Code:
netcat -z -w <timeout in seconds> <host> <port>

So to check to see if ssh will respond withing 5 seconds, so the following:

Code:
netcat -z -w 5 host.example.com 22 || /bin/some_custom_alert

The '-z' option will make it disconnect as soon as it makes a connection to the port, and of course '-w' is to set the timeout in seconds.

If it does not connect, it will return a non-zero exit status, in which case, you would know to raise your alarm.

Hope this helps...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

passing input into a cmd line that's waiting for a response

Hi, I am writing a little script to update a parameters on JMQ. however the JMQ requires a "y" confirmation to be input as part of the cmd I am running. However I want run this script to offline with no input from a user. it works if a I create a file with with just y in it and pass that in... (3 Replies)
Discussion started by: shropshirehobbi
3 Replies

2. Shell Programming and Scripting

How to skip command if it is hanging while waiting for response

Hello, I have a script that contains the command "whois 1.2.3.4" Sometimes this command takes far too long to produce any output and as a result the rest of the script is not executed. Can anyone suggest a method so that if no output is produced after say 2 seconds the script skips that... (2 Replies)
Discussion started by: colinireland
2 Replies

3. UNIX for Advanced & Expert Users

ssh error: Error reading response length from authentication socket

Hi - I am getting the error `Error reading response length from authentication socket' when I ssh from my cluster to another cluster, and then back to my cluster. It doesn't seem to affect anything, but it's just annoying that it always pops up and tends to confuse new users of the cluster. I... (1 Reply)
Discussion started by: cpp6f
1 Replies

4. Shell Programming and Scripting

Capture RSA fingerprint from ssh response

Hi. I'm trying to automate access to an Amazon Web Services machine instance. What this means is that my script is trying to use ssh to connect to a new server every time. I know the RSA fingerprint of my new server through an out-of-band channel. I would like to capture the RSA fingerprint... (0 Replies)
Discussion started by: chorlton
0 Replies

5. Shell Programming and Scripting

not waiting...why?

My shell script is not waiting. I right click on a file and say convert it to whatever and it runs this script. It converts it using Compressor but I want it to wait until it is 100% done before moving on and it is not waiting. I have tried to put it in the background and using "wait". I have tried... (10 Replies)
Discussion started by: mainegate
10 Replies

6. Shell Programming and Scripting

not waiting

I have a script that runs Compressor and converts the file then I want it to inject the file with Flvtool2. My script works fine but the flvtool2 is starting too early. I have tried to put it in the background by putting a "&" sign at the end and then put a "wait" on a new line. Anyone have any... (2 Replies)
Discussion started by: mainegate
2 Replies

7. Shell Programming and Scripting

how do I handle ssh response with expect

I am trying to write an expect script that trys to telnet, if telnet fails, trys to ssh to a remote network devices. The script works fine until the following is received : spawn telnet 10.3.2.24 Trying 10.3.2.24... telnet: connect to address 10.3.2.24: Connection refused 10.3.2.24 is... (2 Replies)
Discussion started by: popeye
2 Replies

8. Shell Programming and Scripting

waiting

I have a text file which contain all the parameters need for scheduled jobs, then this "control" script would be called everynight at certain time while read line do $myScript.sh $line & pid=$! i=`expr $i + 1` done < $list then I need to wait until all... (1 Reply)
Discussion started by: mpang_
1 Replies

9. Shell Programming and Scripting

Looping and waiting

Hi Is it possible to have a script run in a loop (waiting for a change of state in the network interface), and if the loop continues for five minutes, to have it email the admin, and carry on in the loop? Here is my loop: #!/bin/bash STATE=`echo "show... (3 Replies)
Discussion started by: mikie
3 Replies

10. Shell Programming and Scripting

read-waiting for user response

Would there be any reason for why a 'read ans' would not wait for a user's response (i.e user has to hit a key to continue)? I know for sure that it is doing everything else in that part of my 'if' statement but it doesn't wait for me to hit a key before continuing. The strange thing is that... (4 Replies)
Discussion started by: giannicello
4 Replies
Login or Register to Ask a Question