title: Checking SSH failure in a script
body: <p>Hi what is the best way to check to see if SSH fails for whatever reason?
  Can I use a IF statement ( if it fails then do something)
  I'm using the ssh command in a loop and passing my hosts names form a flat file.</p>
  
  <p>so I do something like: </p>
  
  <pre><code>for i in `cat /tmp/hosts` ; do ssh $i 'hostname;sudo ethtool eth1'; done
  </code></pre>
  
  <p>I get sometime this error or I just cannot connect </p>
  
  <pre><code>ssh: host1 Temporary failure in name resolution
  </code></pre>
  
  <p>I want to skip the hosts that I cannot connect to is SSH fails. What is the best way to do this? Is there a runtime error I can trap to bypass the hosts that I cannot ssh into for whatever reason, perhaps ssh is not allowed or I do not have the right password ?</p>
  
  <p>Thanking you in advance 
  Cheers</p>