0

I'm trying to come up with a very simple implementation for this problem:

  • I have 2 environments behaving under a master-slave paradigm
  • Environment A manages environment B: configures it, runs scripts in it, etc.
  • Environment B cannot initiate communications with environment A
  • Sometimes environment A leaves scripts running in environment B's background [./myScript.sh &], and has no way of knowing when those scripts are finished (well, environment A could just poll B with ps -aux, but I'm looking for a more generic system)

I'd like to create a system that satisfies these conditions:

  • When a background script myScript.sh finishes, it leaves a message in some mailbox
  • Environment A keeps a runner that periodically checks the mailbox in environment B, and consumes all new messages
  • Adding and consuming messages to this 'queue' must be resistant to race conditions / concurrency
  • The solution must be based on Bash

I thought of 2 options:

  • Option A: modeling the mailbox as a file. myScript.sh appends notifications to the file; environment A reads and empties the file via ssh. I guess race conditions could be solved via file locking? I think bash allows this.
  • Option B: much simpler, myScript.sh would leave messages as separate files in a well-known folder which would act as mailbox. Environment A would get the list of files, cat them and remove them.

But perhaps the vast know-how of StackOverflow will propose must better / simpler options.

Thanks!

ismarlowe
  • 119
  • 2
  • 13
  • Did you already try something? Please share you're code – F. Hauri - Give Up GitHub Jun 22 '23 at 07:01
  • 1
    Machine B: use `echo >>/path/to/logfile "Process $id ended."`, then from machime A: `ssh machineB tail -f /path/to/logfile` in a ***subtask***! See [Detach command from SSH session](https://stackoverflow.com/a/70723607/1765658), [How to run ssh in background while keeping access](https://stackoverflow.com/a/21522587/1765658) and [Sample using `ssh machine tail -f ...`](https://stackoverflow.com/a/73217493/1765658)... And maybe: [How to 'grep' a continuous stream?](https://stackoverflow.com/a/70517999/1765658) – F. Hauri - Give Up GitHub Jun 22 '23 at 07:17
  • Do both "environments" run on the same host? – user1934428 Jun 22 '23 at 14:25

0 Answers0