-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-log-errors.sh
More file actions
executable file
·33 lines (25 loc) · 1.18 KB
/
check-log-errors.sh
File metadata and controls
executable file
·33 lines (25 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
# Output file name
LOG_FILE="system_errors.log"
echo "=== STARTING ERROR COLLECTION - $(date '+%Y-%m-%d %H:%M:%S') ===" > "$LOG_FILE"
echo "Monitoring all active and stopped containers..." >> "$LOG_FILE"
echo "------------------------------------------------------------" >> "$LOG_FILE"
# Get all container names
containers=$(docker ps -a --format "{{.Names}}")
for container in $containers; do
echo "🔎 Analyzing: $container"
# Add header to the file
echo -e "\n>>> CONTAINER: $container" >> "$LOG_FILE"
echo "------------------------------------------------------------" >> "$LOG_FILE"
# Extract errors, exceptions, and critical failures
# Redirect stderr to stdout to ensure everything is captured
errors=$(docker logs "$container" 2>&1 | grep -Ei "error|exception|stacktrace|emerg|fatal|failed|critical|denied|unreachable")
if [ -z "$errors" ]; then
echo " [OK] No critical errors found." >> "$LOG_FILE"
else
echo "$errors" >> "$LOG_FILE"
echo " [!] Errors found and saved."
fi
done
echo -e "\n=== END OF REPORT ===" >> "$LOG_FILE"
echo -e "\nDone! The file '$LOG_FILE' was generated successfully."