I want to use tmux's send-keys
to run a series of commands when I log into a remote server
In the linked answer, a single command is used. I've found that I can put a series of them but I've never gotten more than 2 of them to successfully run. Is it possible to introduce a pause between them (since I assume the problem is one of tmux executing them before the remote host can respond)?
The commands will span a change of the logged-in user, which hasn't been problem so far, but that's one reason I can't simply have a script on the server that I run. (tmux doesn't care if I change user but a script can't do that and then continue running.)
So how can I go beyond just 2 commands?
I doubt it is relevant, but I'm running zsh locally and bash on the server.
tmux send-keys -t s1 username
from a shell script or are you binding keys? If it is a script then just usesleep
in the script. The correct tool to do this is probablyexpect
which can react to the output rather than just typing blindly.sendkeys
one looks like a script to me. Are you actually typingtmux new -dmy_session \; send mycommand Enter
or do you have this in a function or in a file?