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.

  • 2
    Why don't you connect without the password and use public/private key? – YoMismo Jul 15 '14 at 15:46
  • I was told that I couldn't connect that way. While I technically could, it isn't acceptable with the policies that have been put in place. I also have no voice/authority to make that change (quickly?) either. So in my case, in examining the roads of least resistance, this seems to have promise. – Tango Bravo Jul 15 '14 at 16:04
  • 1
    I take it that the remote box doesn't have tmux installed? Otherwise it would be much better to ssh into the remote box and only then launch tmux. // Also, I'd suggest that you make use of your ~/.ssh/config file: put Host foo, User user and Hostname example.com on three consecutive lines in the config file. Then ssh foo becomes equivalent to ssh user@example.com. // Maybe something like this helps, too: command-prompt -p 'log in as:' -I 'user@example.com' 'split-window -v -d %1; split-window -v -d %1' – damien Jul 16 '14 at 23:06

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'
  • So by "not connected to other functionality" you mean the channel is just a name in its own namespace and unrelated to tmux's predefined "events"? – ormaaj Aug 11 '19 at 19:31
  • There might still be a race issue if wait-for -S doesn't guarantee message delivery and the sync-command finishes before wait-for. – ormaaj Aug 11 '19 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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