Created
June 20, 2024 17:36
-
-
Save teebow1e/e093d0bce37a150fe4eb78b7b8689785 to your computer and use it in GitHub Desktop.
simulate a webserver writing log to a file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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