Ssh – Have tmux wait until I SSH in, to complete rest of Tmuxinator script

linuxsshtmux

After recently discovering tmux and Tmuxinator, I've been trying to set up a development environment to use.

Per protocol, we aren't allowed to store passwords/passphrases in scripts. So what I'm looking for is a wait for tmux to wait for the SSH tunnel to get set up (password supplied, enter pressed, and logged in).

I know that there's a "wait-for" command in tmux 1.8+. I'm running 1.9a via Cygwin. But even though I've read over the documentation, I'm just having a difficult time understanding it.

tmux new-session -s development -n editor -d
tmux split-window -v
tmux split-window -v

"Need to send to all panes.
tmux send-keys -t development 'ssh user@example.com' C-m

So, here's a very simple version of what I have.

Thoughts? I know I can synchronize-sessions, I'm still working out the kinks in this.

Edit:
Looking into commands, and pulling variables from the pane to the command from synchronized-panes. This might be a "better" way to go about, until I can figure out how to get TMUX to prompt me for user-input.

Might issue a feature request.

Best Answer

Some notes of wait-for

So the basic usage of wait-for isn't too complicated if you think of it as analogous to threading concurrency primitives

It's not really connected to other tmux functionality, just a convenient implementation of IPC.

wait-for event_name is like waiting for an event wait-for -S event_name is a means of signalling an event

The -U and -L options are kind of orthogonal and act like semaphores

Addressing your question directly

You can solve these sorts of race condition with wait-for but only if commands are synchronous.

tmux send-keys 'sync-command ; tmux wait-for -S command-finished' C-m
tmux wait-for command-finished

The problem that you have here is that ssh command isn't synchronous: you can't tell when it has finished.

Looking through the manual we can find the LocalCommand directive which seems to do what we want: run a command locally after the connection has finished so we can call

ssh root@iris.tatw.name -o 'PermitLocalCommand yes' -o 'LocalCommand  tmux wait-for -S done'