Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there any way I could trigger a bash script when ssh times out?

I have an alias to set the tmux title when starting ssh. The alias also includes a title change after the ssh session, which works if I do a clean exit, but if the session times out, the rest of the alias doesn't run.

share|improve this question

Wrap ssh with a shell script instead of an alias:

 echo "Setting up tmux and stuff..."
 # set up tmux and stuff

 ssh "$@"

 echo "Cleaning up..."
 # clean up
share|improve this answer
The only thing, it's not great with nested ssh connections. Otherwise it works perfect. – rush Sep 6 '13 at 13:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.