On 17/01/2021 14:32, Martin Gregorie wrote:
> On Sun, 17 Jan 2021 10:39:32 +0000, Pancho wrote:
>
>> However, I'm not yet convinced this is a sensible way of observing
>> events. I'm still undecided.
>>
> That depends: if the occurrence of events to be observed cause messages
> to be logged rather than being dealt with by the program that observes
> them, then watching a log for the occurrence might well be the best way
> to do it since this separates the observation from the consequent action,
> offering the possibility of more than one observing process being able to
> trigger the action. Where that action is irreversable, as it is in this
> case, that sounds like a good idea.
>
> Of course, if the observer doesn't log anything, there's no reason to use
> a general purpose logfile - just write the observations to a file or
> pipeline that's accessable to the process that will execute the action:
> as this is Linux, you can use shared memory or a semaphore (if the
> programming language supports it) to signal that an actionable event has
> occurred. Shared memory, event queues and asynchronous i/o are all
> available in the C and Java standard function/class libraries but may not
> be in other languages.
>
> OTOH if the required action is specific to the observer, i.e. doesn't
> affect anything outside the process(es) handling the data stream being
> observed, then simply deal with the observation inside the observing
> process.
>
>
Yeah, I'm not sure what you mean, the journal/logfile is the "subject",
the "observer" logging isn't relevant.
FWIW I got this basic pattern to work.
--
journalctl -f | awk -W interactive -- '/Specific Event/ { system(
"/home/pi/SpecificEventHandler.sh") }'
--
Response appears to be ballpark of 30ms on a rPi3. Tested with:
date +%S-%N;logger "Specific Event"
And /home/pi/SpecificEventHandler.sh
--
#!/bin/bash
touch "awktest$(date +%H-%M-%S-%N)"
-
I'm not sure what awk interactive/buffering means. Without the "-W
interactive" flag awk doesn't just buffer output, the system() call is
delayed too. It's more like it is buffering input.
--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)
|