0

I find myself having to do a series of ssh in order to get to a particular host. What I currently do is to copy and paste the commands into the terminal, one after the another, like a machine. I'm wondering if there's a way replay these fixed commands into my terminal.

I do use tmux, and I'm aware of tmux send; but I'd want to be doing this "intelligently", in that I want to wait for the prompt before I send the next ssh command. I'm also aware of expect, but the usages I've seen are where the terminal is spawned from within the script and interacted from within—and the spawned terminal dies with the expect script.

What would be ideal is if I can get expect to do its thing on the very terminal that I've open. Is there a way to do that, or are there alternatives?

2
  • 1
    With expect, you can spawn a shell (that lives inside the terminal window), and the spawned shell can remain open if you choose to interact with the shell at the end of the expect script. Commented Oct 20, 2022 at 13:34
  • One cool tmux feature is that you can split the window into subpanes. Each subpane can ssh to a different host. Then the panes can be synchronized so that typing (or pasting) into one pane is mirrored in all the other panes simultaneously Commented Oct 20, 2022 at 13:36

1 Answer 1

0

I ended up using expect's interact command, as one of the comments above mention. The general template is like this:

spawn ssh ...
send "some keys"
expect {
  ...
}
interact

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .