I have a bash script which uses "ssh -t -t <destination> <command>" to invoke a command on a remote machine. <command> is a script which invokes minicom with runscript, which is why I use the "-t -t" flags. The problem is, sometimes the executable running on minicom's target hangs. Runscript has a global timeout, but I can't find any way to execute a command upon global timeout, or else I'd have the global timeout issue "killall -9 minicom" to kill the minicom session. The runscript times out but the minicom session remains open. So now I need a way to timeout the ssh session from within the bash script.

The following works fine from the shell and from within the bash script:
timeout 100m ssh <destination> echo hi
timeout 100m ssh -t <destination> echo hi
timeout 100m ssh -t -t <destination> echo hi

However, if I put the timeout inside a bash script, the first line above works well but as soon as I add a -t flag, the script appears to hang instead of running the command on the remote server. I can't even ^C out of it. The remote server does not start ever start executing the command sent (verified by sending a long running script, watching the local bash script with the timeout hang, and seeing the remote server *not* running that process at the same time).

Any ideas of why this his happening? Any suggestions for solutions?