1

I have a stream A and a value B. The stream contains timestamps, the value B is a timestamp too. The stream A is updated sometimes with a new line, containing a new timestamp. The value of B remains constant.

The aim is to output a system message, as soon as time A is bigger than time B. This task should be done in bash.

My Idea is listening to file A using dbus-monitor "some arguments" | egrep --line-buffered "Timestamp:*" |, followed by a while read -r line ; do command.

Is it possible to implement two "real-time"-actions within a bash script? E.g. An EventHandler, in order to fire the system message, as soon as my condition is true? Or will I have to use cron? (The system message may also be delayed by two seconds…)

AnatraIlDuck
  • 283
  • 2
  • 8

1 Answers1

2

I'm a little unclear on exactly what you want to have happen, so this may only be half an answer:

It's certainly possible to run commands in parallel in bash, which is what I think you are asking in the latter portion of your question. Given two shell functions:

some_command() {
    do_something
}

another_command() {
    do_something_else
}

You can then run:

some_command &
another_command &
wait

At this point, both some_command and another_command are running the background, and the wait commands causes your script to wait until both background processes exit.

You can get a lot fancier (e.g., wait can accept a pid to wait for a specific process, and you can use kill to stop a background process if you need to terminate it early, etc).

larsks
  • 277,717
  • 41
  • 399
  • 399
  • this seems a fine idea, and with some addition details I think I can solve what I was looking for: in order to exchange variables between both functions, I will use a temporary file or so: http://stackoverflow.com/questions/13207292/bash-background-process-modify-global-variable – AnatraIlDuck Jan 21 '14 at 18:58