Commit | Line | Data |
---|---|---|
6cbe7c0a SBS |
1 | #!/bin/bash |
2 | # Desc: Compresses, encrypts, and writes stdin every 5 seconds | |
3 | ||
5938a598 SBS |
4 | #==BEGIN Define script parameters== |
5 | #===BEGIN Initialize variables=== | |
adf766fc | 6 | |
5938a598 | 7 | # Logging Behavior parameters |
adf766fc SBS |
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 | |
5938a598 SBS |
12 | |
13 | # Script Metadata | |
adf766fc | 14 | scriptVersion="0.1.1"; # Define version of script. |
5938a598 | 15 | scriptName="bklog"; # Define basename of script file. |
adf766fc | 16 | PATH="$HOME/.local/bin:$PATH"; # Add "$(systemd-path user-binaries)" path in case user apps saved there |
5938a598 SBS |
17 | |
18 | # Arrays | |
19 | declare -a buffer # Initialize buffer array | |
20 | ||
21 | # Variables | |
22 | ||
23 | #===END Initialize variables=== | |
24 | ||
25 | #===BEGIN Declare local script functions=== | |
6cbe7c0a SBS |
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 | |
5938a598 SBS |
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 | |
34 | main() { | |
35 | bufferRound=0; | |
36 | # Run until script TTL seconds pass | |
37 | while [[ $SECONDS -lt "scriptTTL" ]]; do | |
38 | bufferTOD="$((SECONDS + bufferTTL))"; | |
39 | lineCount=0; | |
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 | |
43 | buffer+=("$line"); | |
44 | echo "DEBUG:Processing line:$lineCount"; | |
45 | echo "DEBUG:Current line :$line"; | |
46 | echo "DEBUG:buf elem count :${#buffer[@]}"; | |
47 | ((lineCount++)); | |
48 | done; | |
49 | # Export buffer to asynchronous processing. | |
50 | magicProcessWriteBuffer & | |
51 | unset buffer; # Clear buffer array for next bufferRound | |
52 | # Increment buffer round | |
53 | ((bufferRound++)); | |
54 | done; | |
6cbe7c0a SBS |
55 | } |
56 | ||
5938a598 SBS |
57 | #===END Declare local script functions=== |
58 | #==END Define script parameters== | |
59 | ||
60 | #==BEGIN Perform work and exit== | |
61 | main "$@" # Run main function. | |
62 | exit 0; | |
63 | #==END Perform work and exit== | |
64 | ||
65 | # Author: Steven Baltakatei Sandoval; | |
6cbe7c0a | 66 | # License: GPLv3+ |