This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
2018-10-03 03:10:49 +01:00
|
|
|
#!/bin/sh
|
2018-10-02 18:38:10 +01:00
|
|
|
|
2018-10-03 03:10:49 +01:00
|
|
|
# CSV file name
|
2018-10-02 18:27:48 +01:00
|
|
|
FILENAME=$(ls stats-* | tail -n 1)
|
2018-10-03 03:10:49 +01:00
|
|
|
|
|
|
|
# chunk file name
|
|
|
|
CHUNK_FILENAME="current-log-provider-chunk.csv"
|
|
|
|
|
|
|
|
# number of log lines for chunk
|
2018-10-02 18:27:48 +01:00
|
|
|
N=100
|
2018-10-03 03:10:49 +01:00
|
|
|
|
|
|
|
# server port
|
|
|
|
PORT=4870
|
|
|
|
|
|
|
|
# CSV header
|
|
|
|
header=$(head -n 1 "$FILENAME")
|
|
|
|
|
2018-10-02 18:27:48 +01:00
|
|
|
while true; do
|
2018-10-03 03:10:49 +01:00
|
|
|
# We don't want repeated headers
|
|
|
|
if [ $(wc -l < "$FILENAME") -gt "$N" ]; then
|
|
|
|
{ echo "$header"; tail -n "$N" $FILENAME; } > "$CHUNK_FILENAME"
|
|
|
|
else
|
|
|
|
cp -f -- "$FILENAME" "$CHUNK_FILENAME"
|
|
|
|
fi
|
2018-10-03 21:28:38 +01:00
|
|
|
{ printf "HTTP/1.0 200 OK\r\nContent-Type: text/csv\r\nContent-Length: $(wc -c <"$CHUNK_FILENAME")\r\nAccess-Control-Allow-Origin: *\r\n\r\n"; cat "$CHUNK_FILENAME"; } | nc -q 0 -v -l -p "$PORT"
|
2018-09-22 18:22:25 +01:00
|
|
|
done
|