b908ad90cb946b7fbb5b349bb5e9d69253b1aed1
2 # Desc: Compresses, encrypts, and writes stdin every 5 seconds
4 #==BEGIN Define script parameters==
5 #===BEGIN Initialize variables===
7 # Logging Behavior parameters
8 scriptTTL_TE
="day"; # Time element at the end of which script terminates
9 scriptTTL
="15"; # (temp) Time (seconds) until script terminates
10 bufferTTL
="5"; # Time-to-live (seconds) for each buffer round
11 dirTempDefault
="/dev/shm"; # Default parent of working directory
14 scriptVersion
="0.1.1"; # Define version of script.
15 scriptName
="bklog"; # Define basename of script file.
16 PATH
="$HOME/.local/bin:$PATH"; # Add "$(systemd-path user-binaries)" path in case user apps saved there
19 declare -a buffer
# Initialize buffer array
23 #===END Initialize variables===
25 #===BEGIN Declare local script functions===
26 yell
() { echo "$0: $*" >&2; } #o Yell, Die, Try Three-Fingered Claw technique
27 die
() { yell
"$*"; exit 111; } #o Ref/Attrib: https://stackoverflow.com/a/25515370
28 try
() { "$@" || die
"cannot $*"; } #o
29 magicProcessWriteBuffer
() {
30 printf "%s\\n" "${buffer[@]}" |
cat |
cat |
cat >> "/dev/shm/$(date +%s)..bkFreqWrite-output1.txt";
31 printf "%s\\n" "${buffer[@]}" |
cat |
cat |
cat >> "/dev/shm/$(date +%s)..bkFreqWrite-output2.txt";
32 printf "%s\\n" "${buffer[@]}" |
cat |
cat |
cat >> "/dev/shm/$(date +%s)..bkFreqWrite-output3.txt";
33 } # Process and Write buffer
36 # Run until script TTL seconds pass
37 while [[ $SECONDS -lt "scriptTTL" ]]; do
38 bufferTOD
="$((SECONDS + bufferTTL))";
40 # Consume stdin to fill buffer until buffer time-of-death (TOD) arrives
41 while read -r -t "$bufferTTL" line
&& [[ $SECONDS -lt "$bufferTOD" ]]; do
42 # Append line to buffer array
44 echo "DEBUG:Processing line:$lineCount";
45 echo "DEBUG:Current line :$line";
46 echo "DEBUG:buf elem count :${#buffer[@]}";
49 # Export buffer to asynchronous processing.
50 magicProcessWriteBuffer
&
51 unset buffer
; # Clear buffer array for next bufferRound
52 # Increment buffer round
57 #===END Declare local script functions===
58 #==END Define script parameters==
60 #==BEGIN Perform work and exit==
61 main
"$@" # Run main function.
63 #==END Perform work and exit==
65 # Author: Steven Baltakatei Sandoval;