feat(bklog):Add metadata, version
[EVA-2020-02.git] / exec / bklog
... / ...
CommitLineData
1#!/bin/bash
2# Desc: Compresses, encrypts, and writes stdin every 5 seconds
3
4#==BEGIN Define script parameters==
5#===BEGIN Initialize variables===
6# Logging Behavior parameters
7scriptTTL="15";
8bufferTTL="5";
9
10# Script Metadata
11scriptVersion="0.1.0"; # Define version of script.
12scriptName="bklog"; # Define basename of script file.
13
14# Arrays
15declare -a buffer # Initialize buffer array
16
17# Variables
18
19#===END Initialize variables===
20
21#===BEGIN Declare local script functions===
22yell() { echo "$0: $*" >&2; } #o Yell, Die, Try Three-Fingered Claw technique
23die() { yell "$*"; exit 111; } #o Ref/Attrib: https://stackoverflow.com/a/25515370
24try() { "$@" || die "cannot $*"; } #o
25magicProcessWriteBuffer() {
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
30main() {
31 bufferRound=0;
32 # Run until script TTL seconds pass
33 while [[ $SECONDS -lt "scriptTTL" ]]; do
34 bufferTOD="$((SECONDS + bufferTTL))";
35 lineCount=0;
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
39 buffer+=("$line");
40 echo "DEBUG:Processing line:$lineCount";
41 echo "DEBUG:Current line :$line";
42 echo "DEBUG:buf elem count :${#buffer[@]}";
43 ((lineCount++));
44 done;
45 # Export buffer to asynchronous processing.
46 magicProcessWriteBuffer &
47 unset buffer; # Clear buffer array for next bufferRound
48 # Increment buffer round
49 ((bufferRound++));
50 done;
51}
52
53#===END Declare local script functions===
54#==END Define script parameters==
55
56#==BEGIN Perform work and exit==
57main "$@" # Run main function.
58exit 0;
59#==END Perform work and exit==
60
61# Author: Steven Baltakatei Sandoval;
62# License: GPLv3+