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...

6
  • Not unless you spawn your command wrapped in tmux or screen Commented Jan 29, 2020 at 17:53
  • Be aware that expect's interact command can listen for patterns and automatically do stuff, that may help. Commented Jan 29, 2020 at 17:54
  • 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
    Commented Feb 2, 2020 at 0:04
  • You'll be better served doing some research, of ask a separate question. Commented Feb 2, 2020 at 0:24
  • Just one note: https://superuser.com/questions/tagged/screen refers to display issues, which most likely not what you had in mind.
    – U. Windl
    Commented Feb 2, 2020 at 1:38

0

You must log in to answer this question.

Browse other questions tagged .