2

I'm trying to run an emulator remotely.

Manually:

I open three terminals (usually as tabs in mate-terminal, but that's not important)

In the first, I run 'startemulator'.

In the second, I run 'startuart'. This terminal needs to stay live, as it gives two-way communication to the emulated device over it uart.

Then I have to wait until the emulated device prints [RDY] over its uart. This takes about 10 minutes, but the time is variable.

Only then can I run 'starthost' in the third terminal. Followed by some other commands which are always the same, including logging in to the host machine. If I do this too early, before the device is ready, all hell breaks loose.

Once this is done, I end up with three terminals, all of which are independently useful.


How can I automate this process (without rejigging all the underlying scripts, which aren't under my control, and which other people depend on)?

I'd like to be able to type 'go', and then go and make a cup of coffee and come back to find it all three terminals set up and waiting for me.

I know that I can use 'expect' for the command sequence in the third terminal, but I don't know how to make it wait for something to be printed in another terminal. I could use a delay, but that's kludgy and fragile.

John Lawrence Aspden
  • 17,124
  • 11
  • 67
  • 110
  • 3
    If you can't use cron or like me recommending you using [screen](https://www.gnu.org/software/screen/manual/screen.html). The `screen's` startup script can start as many sessions as you need. – clt60 Feb 09 '17 at 12:27
  • I would love to use screen, but can it start a process in one terminal conditional on [RDY] getting printed in another one? – John Lawrence Aspden Feb 09 '17 at 12:35
  • 1
    The screen is complex. Here are probably more different solutions, one for example could be using the `screenlog`, e.g. the output from the `startuart` session will be logged into a file and in the third session will just wait and periodically check the `RDY` in the logfile. Of course, this is an pure speculation without real testing. – clt60 Feb 09 '17 at 12:54
  • ... another one could be: use the `expect` to monitor the output from the `startuart` and when the `expect` detects the `RDY` will start the third session with the `starthost`... – clt60 Feb 09 '17 at 13:00
  • 3
    You could use a fifo for synchronisation. Run `expect` in the second terminal and wait for`RDY` and then write to a fifo. In the third terminal, do a read from the fifo and that will block till the second terminal has seen `RDY` and sent a string through the fifo. – Mark Setchell Feb 09 '17 at 13:32
  • I would use tmux for this task. Actally, there is a very neat presentatio (given by Chris Hunt), where he shows how to automate tmux https://www.youtube.com/watch?v=vHdiXoHKSgU – Julian Mar 12 '17 at 11:19

0 Answers0