chore(unitproc):bkFreqWrite:Update debug messages
[BK-2020-03.git] / unitproc / bkFreqWrite
CommitLineData
045dc2fb 1#!/bin/bash
cc460307 2# Desc: Writes stdin to disk every 5 seconds
045dc2fb 3
cc460307 4yell() { echo "$0: $*" >&2; } #o Yell, Die, Try Three-Fingered Claw technique
d642682d
SBS
5die() { yell "$*"; exit 111; } #o Ref/Attrib: https://stackoverflow.com/a/25515370
6try() { "$@" || die "cannot $*"; } #o
045dc2fb 7
9988125c
SBS
8declare -a buffer # Initialize buffer array
9scriptTTL="15";
10bufferTTL="5";
d642682d 11
9988125c 12magicWriteBuffer() {
63ef0127
SBS
13 printf "%s\n" "${buffer[@]}" | cat | cat | cat >> /dev/shm/$(date +%s)..bkFreqWrite-output1.txt;
14 printf "%s\n" "${buffer[@]}" | cat | cat | cat >> /dev/shm/$(date +%s)..bkFreqWrite-output2.txt;
15 printf "%s\n" "${buffer[@]}" | cat | cat | cat >> /dev/shm/$(date +%s)..bkFreqWrite-output3.txt;
9988125c 16}
d642682d 17
17fda1d5 18bufferRound=0;
9988125c
SBS
19# Run until script TTL seconds pass
20while [[ $SECONDS -lt "scriptTTL" ]]; do
21 bufferTOD="$((SECONDS + $bufferTTL))";
17fda1d5
SBS
22 lineCount=0;
23 # Consume stdin to fill buffer until buffer time-of-death (TOD) arrives
9988125c
SBS
24 while read -r line && [[ $SECONDS -lt "$bufferTOD" ]]; do
25 # Append line to buffer
26 buffer+=("$line");
cc460307
SBS
27 echo "DEBUG:Processing line:$lineCount";
28 echo "DEBUG:Current line :$line";
29 echo "DEBUG:buf elem count :${#buffer[@]}";
9988125c
SBS
30 ((lineCount++));
31 done;
32 # Export buffer to asynchronous processing.
33 magicWriteBuffer &
34 unset buffer;
35 # Increment buffer round
36 ((bufferRound++));
d642682d 37done;
17fda1d5
SBS
38
39# Author: Steven Baltakatei Sandoval
40# License: GPLv3+