I am improving a script made by third parts.
The script runs on a Ubuntu OS.
This scripts contains a loop in which about there are about 10 if statements (they involve only localhost), and each one contains a ssh
command.
So it works like this:
the code loops over a list of host machine names,
if a condition is met, the server will ssh into another server, access a database (by using a custom connection command - so that one does not have to specify each time the password, port, etc. to access the DB) and stores some information into a variable.
The ssh commands have the ConnectTimeout
option set.
They look like this :
ssh hostmachine_${i} -o ConnectTimeout=$X "custom_psql -U $my_db_user -h c${i} $db_name -A -t -c \"select * from my_table;"\"
( $i
contains the remote server name )
I am testing this script with the scenario that no remote server is reachable via ssh, so every time a condition is met, the ssh command should print the output Connection timed out during banner exchange
and then go to the next command.
However, after this happens for the first N
conditions met (N
varies), the code exeeds the X
seconds and stands by, waiting for the ssh connection to open, as if the ssh command did not have the ConnectTimeout
option enabled.
I have launched the same ssh command it over and over in my terminal and it seems the triggering/not-triggering of the ConnectTimeout option does not depend just from the time that passes between one ssh command launch and another, it also depends from how much time a ssh command remained waiting for the connection to open, before I keyboardinterrupt the process.
I have searched the internet, but I cannot find any trace of this issue.
Can anybody help me?