Is it possible to detach and re-attach to a spawned process using separate expect processes?

0

I have an expect script that spawns a process, then does some initialization (authentication), then performs some task that needs prior authentication.

Considering to extend the script to execute multiple tasks after initialization, I wondered whether I could use separate expect processes to perform each task (once the spawned process terminates it needs to re-authenticate).

So that would mean:

  1. First expect spawns a process and does initialization. Then expect exists, but leaves the spawned process active.

  2. For each task to perform: Start another expect process that re-attaches to the process spawned earlier. This step would repeat as often as needed.

  3. A final expect re-attaches to the spawned process and does a clean shutdown of that process.

Is that possible? The advantage would be that for many tasks, a script could be created on the fly, being executed, and then replaced by the next task's script. Otherwise I would have a very lengthy script...

U. Windl

Posted 2020-01-29T09:05:50.890

Reputation: 143

Not unless you spawn your command wrapped in [tag:tmux] or [tag:screen] – glenn jackman – 2020-01-29T17:53:36.287

Be aware that expect's interact command can listen for patterns and automatically do stuff, that may help. – glenn jackman – 2020-01-29T17:54:16.607

On tmux and screen: Could you give an example, maybe using ssh to log in to some host "interactively", the send more commands to the ssh connection? I'm not quite sue how a solution might look like. – U. Windl – 2020-02-02T00:04:57.050

You'll be better served doing some research, of ask a separate question. – glenn jackman – 2020-02-02T00:24:02.993

Just one note: https://superuser.com/questions/tagged/screen refers to display issues, which most likely not what you had in mind. – U. Windl – 2020-02-02T01:38:31.373

No answers