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