bash - How to continually process last lines of two files when the files change randomly? -
i have following simple snippet:
#!/bin/bash tail -f "data/top.right.log" | while read val1 val2=$(tail -n 1 "data/top.left.log") echo $(echo "$val1 - $val2" | bc) done
top.left.log
, top.right.log
files other processes continually write. bash script subtracts last lines of both files , show result.
i make script more efficient. in pseudo-code this:
#!/bin/bash magiccommand "data/top.right.log" "data/top.left.log" | while read val1 val2 echo $(echo "$val1 - $val2" | bc) done
so whenever top.left.log
or top.right.log
changes echo command called.
i have tried various snippets stackoverflow rely on fact files not change or both files contain same amount of lines not case.
if have inotify-tools
can use following command:
inotifywait -q -e modify file1 file2
description:
inotifywait efficiently waits changes files using linux's inotify(7) interface. suitable waiting changes files shell scripts. can either exit once event occurs, or continually execute , output events occur.
an example:
while : ; inotifywait -q -e modify file1 file2 echo `tail -n1 file1` echo `tail -n1 file2` done
Comments
Post a Comment