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