Skip to content

Instantly share code, notes, and snippets.

@teebow1e
Created June 20, 2024 17:36
Show Gist options
  • Select an option

  • Save teebow1e/e093d0bce37a150fe4eb78b7b8689785 to your computer and use it in GitHub Desktop.

Select an option

Save teebow1e/e093d0bce37a150fe4eb78b7b8689785 to your computer and use it in GitHub Desktop.
simulate a webserver writing log to a file
#!/bin/bash
SOURCE_FILE="access_log_1000.log"
TARGET_FILE="/mnt/c/Users/teebow1e/IdeaProjects/project1-soict/webserver.log"
#TARGET_FILE="target.log"
CHUNK_SIZE=5
while true; do
chunk=$(head -n "$CHUNK_SIZE" "$SOURCE_FILE")
if [ -n "$chunk" ]; then
echo "$chunk" >> "$TARGET_FILE"
sed -i "1,${CHUNK_SIZE}d" "$SOURCE_FILE"
fi
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment