title: Bash script pass ssh command to remote server and bring back the prompt
body: <p>I am restarting bunch of remote servers via bash script but the script waits for me to break before moving on.</p>
  <pre><code>#!/bin/bash
  main()
  {
          hostlist=(&quot;server1&quot; &quot;server2&quot;)
          echo -e &quot;----- Reatsrting all servers -----&quot;
          for host in ${hostlist[@]};
          do
                  echo &quot;----- Restarting $host -----&quot;
                  ssh -t $host &quot;sudo reboot -f now&quot;
                  echo &quot;----- Restart of $host complete -----&quot;
          done
          echo &quot;----- All servers restarted -----&quot;
  }
  main
  </code></pre>
  <p>The result of above script is</p>
  <pre><code>----- Reatsrting all servers -----
  ----- Restarting server1 -----
  packet_write_wait: Connection to 10.10.1.11 port 22: Broken pipe
  ----- Restart of server1 complete -----
  ----- Restarting server2 -----
  packet_write_wait: Connection to 10.10.1.12 port 22: Broken pipe
  ----- Restart of server2 complete -----
  ----- All servers restarted -----
  </code></pre>
  <p>If you notice the &quot;<strong>packet_write_wait: Connection to ...</strong>&quot;, this happens as the server takes time to restart and i have to manually break it by hitting enter, when i do that i get the packet_write_wait line and the script moves on with next code.</p>
  <p>Is there a way by which i can just shoot the restart command and forget so i can move on with the rest of the script (get my prompt back without manually intervening)?</p>