12

I have a list of full remote host ip addresses. I wrote a script to connect all the hosts in this list, one by one. My question is, sometimes when an IP address is down, script waits for a while (maybe a couple of minute) to go and execute next host. So I would like to decrease this waiting time. For example after 10 s, I want ssh connection is timeout and my script tries the next IP address. So how I can tweak this?

Thanks

1

1 Answer 1

24

if you call ssh script you can use something like that

ssh -o ConnectTimeout=10  <hostName>

where 10 is the number of seconds

Sign up to request clarification or add additional context in comments.

3 Comments

Actually I try to do something like: ssh-keygen for HOST in $(cat /scripts/ip_list); do ssh-copy-id -i ~/.ssh/id_rsa.pub ${HOST} done So I don't know where I can use -o option. I can try something like [code] cat ~/.ssh/id_rsa.pub | ssh -o ConnectTimeout=10 username@${HOST} 'cat >> .ssh/authorized_keys' but the thing is, some of these remote home directories don't have a ~/.ssh folder. So command will fail when it couldn't find ~/.ssh/authorized_keys
how to add milliseconds value to timeout ?
As far as I know, ssh option ConnectTimeout has granularity of 1 second and minimum you can use is 1 second. I agree that for local network connections setting timeout to say 50-100 ms could make sense. If you need to rapidly connect to other servers, see settings ControlMaster, ControlPath and set ControlPersist 1.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.