Debugging a Log Rotation Pipeline — Manual Trace
Advanced
60 min
0 views
0 solutions
Overview
A log-rotation cron job at LogShipper is silently deleting logs instead of archiving them. The manager must trace the bash script logic by hand to find the bug before data loss escalates.
Case Details
# Aplly.xyz Case Study Submission
## Title
Debugging a Log Rotation Pipeline — Manual Trace
## Type
Technology/IT
## Difficulty
Advanced
## Estimated Time
60 minutes
## Overview
A log-rotation cron job at LogShipper is silently deleting logs instead of archiving them. The manager must trace the bash script logic by hand to find the bug before data loss escalates.
## Case Details
Function Focus: Manual code tracing, shell script logic, off-by-one reasoning
Scenario:
The compliance team noticed that archived logs for the past 3 days are missing. The log-rotation script has been running on schedule but producing empty archives. The manager has the bash script, the cron config, and sample directory state. No error messages appear in syslog. They must trace execution by hand.
Dataset Structure:
- Bash script pseudocode (~30 lines): log rotation with retention policy
- Cron schedule entry
- Directory listing before and after a rotation cycle
- Expected vs actual archive sizes
Tasks:
1. Trace the bash script line by line for a 7-day rotation cycle — manually, without pasting the script into any AI or LLM tool
2. Create a trace table showing variable state (CURRENT_DAY, ARCHIVE_NAME, FILE_LIST) after each iteration
3. Identify the exact line causing the bug and explain why it fails silently
4. Propose a fix and write one test command that would have caught this before production
5. Only after submitting: paste the script into an LLM and compare your trace with its output
Expected Output:
A trace table (one row per day iteration showing key variable states), the identified bug line with explanation, proposed fix, and a regression test command.
Evaluation Criteria:
Correct manual trace matching the actual execution path, accurate bug identification with line reference, and a regression test that targets the root mechanism (not a generic "add error handling").
## Data Sources
Bash script (log-rotation.sh):
```
#!/bin/bash
LOG_DIR="/var/log/app"
ARCHIVE_DIR="/var/log/archive"
RETENTION_DAYS=7
CURRENT_DAY=$(date +%u)
# Archive yesterday's log
YESTERDAY_INDEX=$((CURRENT_DAY - 1))
if [ $YESTERDAY_INDEX -eq 0 ]; then
YESTERDAY_INDEX=7
fi
ARCHIVE_NAME="app-$(date +%Y%m%d).log.gz"
YESTERDAY_LOG="${LOG_DIR}/app.log.${YESTERDAY_INDEX}"
# BUG: Using $ARCHIVE_NAME (today's date) instead of yesterday's date
# when the rotation wraps around Sunday->Monday
if [ -f "$YESTERDAY_LOG" ]; then
gzip -c "$YESTERDAY_LOG" > "${ARCHIVE_DIR}/${ARCHIVE_NAME}"
rm -f "$YESTERDAY_LOG"
fi
# Clean archives older than retention
find "$ARCHIVE_DIR" -name "*.log.gz" -mtime +$RETENTION_DAYS -delete
# Rotate log files
for i in {6..1}; do
if [ -f "${LOG_DIR}/app.log.${i}" ]; then
mv "${LOG_DIR}/app.log.${i}" "${LOG_DIR}/app.log.$((i + 1))"
fi
done
if [ -f "${LOG_DIR}/app.log" ]; then
mv "${LOG_DIR}/app.log" "${LOG_DIR}/app.log.1"
fi
touch "${LOG_DIR}/app.log"
```
Cron entry:
```
0 3 * /usr/local/bin/log-rotation.sh
```
Directory state before Monday's run (after Sunday's rotation):
```
/var/log/app/app.log (current, 0 bytes, just rotated)
/var/log/app/app.log.1 (Mon's log, 45 KB)
/var/log/app/app.log.2 (Tue's log, 52 KB)
/var/log/app/app.log.3 (Wed's log, 38 KB)
/var/log/app/app.log.4 (Thu's log, 41 KB)
/var/log/app/app.log.5 (Fri's log, 55 KB)
/var/log/app/app.log.6 (Sat's log, 47 KB)
/var/log/app/app.log.7 (Sun's log, 44 KB)
```
Expected archive naming: app-YYYYMMDD.log.gz using yesterday's date
Actual archive naming: app-YYYYMMDD.log.gz using today's date
(Diagnostic hint: On Monday morning, CURRENT_DAY=1, YESTERDAY_INDEX=7. The script uses `date +%Y%m%d` for the archive name at line 8, which gives today's date (Monday), not yesterday's (Sunday). The archiving works but the filename is wrong — overwrites the existing Monday archive when the script runs on Tuesday, leading to apparent data loss.)
## Solution Frameworks
Manual trace tables, shell script debugging, off-by-one analysis
## Solver Guidance & Tutorials
Link to: "Tracing Shell Scripts by Hand" tutorial
## What You'll Learn
- Systematic manual tracing of shell script logic
- Detecting silent bugs that produce wrong output instead of crashes
- Writing regression tests that target the root mechanism
## Tags
debugging, shell scripting, log rotation, trace tables
## Registration Links
- Register as Solver
- Register as Evaluator
## Title
Debugging a Log Rotation Pipeline — Manual Trace
## Type
Technology/IT
## Difficulty
Advanced
## Estimated Time
60 minutes
## Overview
A log-rotation cron job at LogShipper is silently deleting logs instead of archiving them. The manager must trace the bash script logic by hand to find the bug before data loss escalates.
## Case Details
Function Focus: Manual code tracing, shell script logic, off-by-one reasoning
Scenario:
The compliance team noticed that archived logs for the past 3 days are missing. The log-rotation script has been running on schedule but producing empty archives. The manager has the bash script, the cron config, and sample directory state. No error messages appear in syslog. They must trace execution by hand.
Dataset Structure:
- Bash script pseudocode (~30 lines): log rotation with retention policy
- Cron schedule entry
- Directory listing before and after a rotation cycle
- Expected vs actual archive sizes
Tasks:
1. Trace the bash script line by line for a 7-day rotation cycle — manually, without pasting the script into any AI or LLM tool
2. Create a trace table showing variable state (CURRENT_DAY, ARCHIVE_NAME, FILE_LIST) after each iteration
3. Identify the exact line causing the bug and explain why it fails silently
4. Propose a fix and write one test command that would have caught this before production
5. Only after submitting: paste the script into an LLM and compare your trace with its output
Expected Output:
A trace table (one row per day iteration showing key variable states), the identified bug line with explanation, proposed fix, and a regression test command.
Evaluation Criteria:
Correct manual trace matching the actual execution path, accurate bug identification with line reference, and a regression test that targets the root mechanism (not a generic "add error handling").
## Data Sources
Bash script (log-rotation.sh):
```
#!/bin/bash
LOG_DIR="/var/log/app"
ARCHIVE_DIR="/var/log/archive"
RETENTION_DAYS=7
CURRENT_DAY=$(date +%u)
# Archive yesterday's log
YESTERDAY_INDEX=$((CURRENT_DAY - 1))
if [ $YESTERDAY_INDEX -eq 0 ]; then
YESTERDAY_INDEX=7
fi
ARCHIVE_NAME="app-$(date +%Y%m%d).log.gz"
YESTERDAY_LOG="${LOG_DIR}/app.log.${YESTERDAY_INDEX}"
# BUG: Using $ARCHIVE_NAME (today's date) instead of yesterday's date
# when the rotation wraps around Sunday->Monday
if [ -f "$YESTERDAY_LOG" ]; then
gzip -c "$YESTERDAY_LOG" > "${ARCHIVE_DIR}/${ARCHIVE_NAME}"
rm -f "$YESTERDAY_LOG"
fi
# Clean archives older than retention
find "$ARCHIVE_DIR" -name "*.log.gz" -mtime +$RETENTION_DAYS -delete
# Rotate log files
for i in {6..1}; do
if [ -f "${LOG_DIR}/app.log.${i}" ]; then
mv "${LOG_DIR}/app.log.${i}" "${LOG_DIR}/app.log.$((i + 1))"
fi
done
if [ -f "${LOG_DIR}/app.log" ]; then
mv "${LOG_DIR}/app.log" "${LOG_DIR}/app.log.1"
fi
touch "${LOG_DIR}/app.log"
```
Cron entry:
```
0 3 * /usr/local/bin/log-rotation.sh
```
Directory state before Monday's run (after Sunday's rotation):
```
/var/log/app/app.log (current, 0 bytes, just rotated)
/var/log/app/app.log.1 (Mon's log, 45 KB)
/var/log/app/app.log.2 (Tue's log, 52 KB)
/var/log/app/app.log.3 (Wed's log, 38 KB)
/var/log/app/app.log.4 (Thu's log, 41 KB)
/var/log/app/app.log.5 (Fri's log, 55 KB)
/var/log/app/app.log.6 (Sat's log, 47 KB)
/var/log/app/app.log.7 (Sun's log, 44 KB)
```
Expected archive naming: app-YYYYMMDD.log.gz using yesterday's date
Actual archive naming: app-YYYYMMDD.log.gz using today's date
(Diagnostic hint: On Monday morning, CURRENT_DAY=1, YESTERDAY_INDEX=7. The script uses `date +%Y%m%d` for the archive name at line 8, which gives today's date (Monday), not yesterday's (Sunday). The archiving works but the filename is wrong — overwrites the existing Monday archive when the script runs on Tuesday, leading to apparent data loss.)
## Solution Frameworks
Manual trace tables, shell script debugging, off-by-one analysis
## Solver Guidance & Tutorials
Link to: "Tracing Shell Scripts by Hand" tutorial
## What You'll Learn
- Systematic manual tracing of shell script logic
- Detecting silent bugs that produce wrong output instead of crashes
- Writing regression tests that target the root mechanism
## Tags
debugging, shell scripting, log rotation, trace tables
## Registration Links
- Register as Solver
- Register as Evaluator
What You'll Learn
- Problem-solving and analytical thinking
- Data-driven decision making
- Business strategy development
- Professional report writing
0
Solutions Submitted
Difficulty
Advanced
Estimated Time
60 minutes
Relevance
Fresh
Source
case-studies-in