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 34ae3df2d4
commit 33bcdb4ef0
+12 -12
View File
@@ -151,9 +151,9 @@ declare -A SIGNATURE_HITS
# Progress indicator
show_progress() {
local count=$1
local total=$2
local percent=$((count * 100 / total))
count=$1
total=$2
percent=$((count * 100 / total))
echo -ne "\r${BLUE}[*]${NC} Processing: $count/$total lines ($percent%) "
}
@@ -187,8 +187,8 @@ echo ""
CAT_CMD="cat"
fi
local file_attacks=0
local line_count=0
file_attacks=0
line_count=0
while IFS= read -r line; do
line_count=$((line_count + 1))
@@ -200,17 +200,17 @@ echo ""
fi
# Analyze line
local result=$(analyze_http_log_line "$line" 2>/dev/null)
local threat_score="${result%%||*}"
result=$(analyze_http_log_line "$line" 2>/dev/null)
threat_score="${result%%||*}"
if [ "$threat_score" -ge "$THRESHOLD" ]; then
local temp="${result#*||}"
local attack_types="${temp%%||*}"
temp="${result#*||}"
attack_types="${temp%%||*}"
temp="${temp#*||}"
local signatures="${temp%%||*}"
signatures="${temp%%||*}"
temp="${temp#*||}"
local ip="${temp%%||*}"
local uri="${temp#*||}"
ip="${temp%%||*}"
uri="${temp#*||}"
# Count attacks
TOTAL_ATTACKS=$((TOTAL_ATTACKS + 1))