title: expect + how to identify if expect break because time out?
body: <p>The target of the following simple expect script is to get the <strong>hostname</strong> name on the remote machine</p>
  
  <p>Sometimes expect script fail to perform ssh to $IP_ADDRESS ( because remote machine not active , etc )</p>
  
  <p>so in this case the expect script will break after 10 second (timeout 10) , this is OK but......</p>
  
  <p>There are two options</p>
  
  <ol>
  <li>Expect script perform ssh successfully , and performed the command hostname on the remote machine</li>
  <li>Expect script break because timeout was 10 seconds</li>
  </ol>
  
  <p>On both cases expect will exit</p>
  
  <ul>
  <li>in case of ssh successfully expect will break after 0.5-1 second but in case of bad ssh then it will break after 10 seconds </li>
  </ul>
  
  <p>but I don’t know if expect script perform ssh successfully or not?</p>
  
  <p>is it possible to identify timeout process ? or to verify that expect ended because timeout?</p>
  
  <p>Remark my Linux machine version  - red-hat 5.1</p>
  
  <p><strong>Expect script</strong></p>
  
  <pre><code> [TestLinux]# get_host_name_on_remote_machine=`cat &lt;&lt; EOF
    &gt; set timeout 10
    &gt; spawn  ssh   $IP_ADDRESS
    &gt;            expect {
    &gt;                      ")?"   { send "yes\r"  ; exp_continue  }
    &gt; 
    &gt;                      word:  {send $PASS\r}
    &gt;                   }
    &gt; expect &gt;  {send "hostname\r"}
    &gt; expect &gt;    {send exit\r}
    &gt; expect eof
    &gt; EOF`
  </code></pre>
  
  <p><strong>Example in case we not have connection to the remote host</strong></p>
  
  <pre><code> [TestLinux]# expect -c  "$get_host_name_on_remote_machine"
   spawn ssh 10.17.180.23
   [TestLinux]# echo $?
   0
  </code></pre>