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

JavaRed
  • 708
  • 4
  • 10
  • 34
  • This is a duplicate of [How to setup SSH timeout in shell script](https://stackoverflow.com/questions/4936807/how-to-setup-ssh-timeout-in-shell-script) – Murmel Jan 15 '18 at 21:48

1 Answers1

24

if you call ssh script you can use something like that

ssh -o ConnectTimeout=10  <hostName>

where 10 is the number of seconds

rderoldan1
  • 3,517
  • 26
  • 33
  • 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 – JavaRed Aug 22 '13 at 19:49
  • 1
    how to add milliseconds value to timeout ? – Sarvnashak Jan 18 '18 at 05:51
  • 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`. – Mikko Rantalainen Nov 19 '20 at 12:41