Fix 'local can only be used in a function' errors in historical analyzer

The code block writing to $OUTPUT_FILE was using 'local' variables
but was not inside a function. The 'local' keyword is only valid inside
functions in bash.

Fixed:
- Removed all 'local' keywords (changed to regular variables)
- Code is in global scope redirected to file, not in a function
- Variables are properly scoped within the { } block

This was causing errors:
  line 190: local: can only be used in a function
  line 203: local: can only be used in a function
  etc.

Now all variables use proper global scope within the output redirection block.

 Syntax validated
This commit is contained in:
cschantz
2025-12-13 02:26:39 -05:00
parent 7b4d3ab8cd
commit 6bc00993c2
+12 -12
View File
@@ -151,9 +151,9 @@ declare -A SIGNATURE_HITS
# Progress indicator # Progress indicator
show_progress() { show_progress() {
local count=$1 count=$1
local total=$2 total=$2
local percent=$((count * 100 / total)) percent=$((count * 100 / total))
echo -ne "\r${BLUE}[*]${NC} Processing: $count/$total lines ($percent%) " echo -ne "\r${BLUE}[*]${NC} Processing: $count/$total lines ($percent%) "
} }
@@ -187,8 +187,8 @@ echo ""
CAT_CMD="cat" CAT_CMD="cat"
fi fi
local file_attacks=0 file_attacks=0
local line_count=0 line_count=0
while IFS= read -r line; do while IFS= read -r line; do
line_count=$((line_count + 1)) line_count=$((line_count + 1))
@@ -200,17 +200,17 @@ echo ""
fi fi
# Analyze line # Analyze line
local result=$(analyze_http_log_line "$line" 2>/dev/null) result=$(analyze_http_log_line "$line" 2>/dev/null)
local threat_score="${result%%||*}" threat_score="${result%%||*}"
if [ "$threat_score" -ge "$THRESHOLD" ]; then if [ "$threat_score" -ge "$THRESHOLD" ]; then
local temp="${result#*||}" temp="${result#*||}"
local attack_types="${temp%%||*}" attack_types="${temp%%||*}"
temp="${temp#*||}" temp="${temp#*||}"
local signatures="${temp%%||*}" signatures="${temp%%||*}"
temp="${temp#*||}" temp="${temp#*||}"
local ip="${temp%%||*}" ip="${temp%%||*}"
local uri="${temp#*||}" uri="${temp#*||}"
# Count attacks # Count attacks
TOTAL_ATTACKS=$((TOTAL_ATTACKS + 1)) TOTAL_ATTACKS=$((TOTAL_ATTACKS + 1))