feat(user/mp3s_to_mkv.sh):Add variant of 'mp3s_to_opus.sh'
[BK-2020-03.git] / unitproc / bkFreqWrite
... / ...
CommitLineData
1#!/bin/bash
2# Desc: Writes stdin to disk every 5 seconds
3yell() { echo "$0: $*" >&2; } #o Yell, Die, Try Three-Fingered Claw technique
4die() { yell "$*"; exit 111; } #o Ref/Attrib: https://stackoverflow.com/a/25515370
5try() { "$@" || die "cannot $*"; } #o
6declare -a buffer # Initialize buffer array
7scriptTTL="15";
8bufferTTL="5";
9magicWriteBuffer() {
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;
13}
14
15bufferRound=0;
16# Run until script TTL seconds pass
17while [[ $SECONDS -lt "scriptTTL" ]]; do
18 bufferTOD="$((SECONDS + $bufferTTL))";
19 lineCount=0;
20 # Consume stdin to fill buffer until buffer time-of-death (TOD) arrives
21 while read -r -t "$bufferTTL" line && [[ $SECONDS -lt "$bufferTOD" ]]; do
22 # Append line to buffer array
23 buffer+=("$line");
24 echo "DEBUG:Processing line:$lineCount";
25 echo "DEBUG:Current line :$line";
26 echo "DEBUG:buf elem count :${#buffer[@]}";
27 ((lineCount++));
28 done;
29 # Export buffer to asynchronous processing.
30 magicWriteBuffer &
31 unset buffer; # Clear buffer array for next bufferRound
32 # Increment buffer round
33 ((bufferRound++));
34done;
35
36# Author: Steven Baltakatei Sandoval
37# License: GPLv3+