2 # Desc: Compresses, encrypts, and writes stdin every 5 seconds
4 #==BEGIN Define script parameters==
5 #===BEGIN Initialize variables===
6 # Logging Behavior parameters
11 scriptVersion
="0.1.0"; # Define version of script.
12 scriptName
="bklog"; # Define basename of script file.
15 declare -a buffer
# Initialize buffer array
19 #===END Initialize variables===
21 #===BEGIN Declare local script functions===
22 yell
() { echo "$0: $*" >&2; } #o Yell, Die, Try Three-Fingered Claw technique
23 die
() { yell
"$*"; exit 111; } #o Ref/Attrib: https://stackoverflow.com/a/25515370
24 try
() { "$@" || die
"cannot $*"; } #o
25 magicProcessWriteBuffer
() {
26 printf "%s\\n" "${buffer[@]}" |
cat |
cat |
cat >> "/dev/shm/$(date +%s)..bkFreqWrite-output1.txt";
27 printf "%s\\n" "${buffer[@]}" |
cat |
cat |
cat >> "/dev/shm/$(date +%s)..bkFreqWrite-output2.txt";
28 printf "%s\\n" "${buffer[@]}" |
cat |
cat |
cat >> "/dev/shm/$(date +%s)..bkFreqWrite-output3.txt";
29 } # Process and Write buffer
32 # Run until script TTL seconds pass
33 while [[ $SECONDS -lt "scriptTTL" ]]; do
34 bufferTOD
="$((SECONDS + bufferTTL))";
36 # Consume stdin to fill buffer until buffer time-of-death (TOD) arrives
37 while read -r -t "$bufferTTL" line
&& [[ $SECONDS -lt "$bufferTOD" ]]; do
38 # Append line to buffer array
40 echo "DEBUG:Processing line:$lineCount";
41 echo "DEBUG:Current line :$line";
42 echo "DEBUG:buf elem count :${#buffer[@]}";
45 # Export buffer to asynchronous processing.
46 magicProcessWriteBuffer
&
47 unset buffer
; # Clear buffer array for next bufferRound
48 # Increment buffer round
53 #===END Declare local script functions===
54 #==END Define script parameters==
56 #==BEGIN Perform work and exit==
57 main
"$@" # Run main function.
59 #==END Perform work and exit==
61 # Author: Steven Baltakatei Sandoval;