Commit | Line | Data |
---|---|---|
045dc2fb | 1 | #!/bin/bash |
cc460307 | 2 | # Desc: Writes stdin to disk every 5 seconds |
cc460307 | 3 | yell() { echo "$0: $*" >&2; } #o Yell, Die, Try Three-Fingered Claw technique |
d642682d SBS |
4 | die() { yell "$*"; exit 111; } #o Ref/Attrib: https://stackoverflow.com/a/25515370 |
5 | try() { "$@" || die "cannot $*"; } #o | |
9988125c SBS |
6 | declare -a buffer # Initialize buffer array |
7 | scriptTTL="15"; | |
8 | bufferTTL="5"; | |
9988125c | 9 | magicWriteBuffer() { |
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 | 15 | bufferRound=0; |
9988125c SBS |
16 | # Run until script TTL seconds pass |
17 | while [[ $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 | |
9988125c | 21 | while read -r 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 | 34 | done; |
17fda1d5 SBS |
35 | |
36 | # Author: Steven Baltakatei Sandoval | |
37 | # License: GPLv3+ |