File tree 1 file changed +35
-0
lines changed 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ # Check if at least one log file is provided
4
+ if [ " $# " -lt 1 ]; then
5
+ echo " Usage: $0 log_file1.log [log_file2.log ...]"
6
+ exit 1
7
+ fi
8
+
9
+ # Temporary file to store combined results
10
+ TEMP_FILE=" combined_results.txt"
11
+
12
+ # Clear the temporary file if it exists
13
+ > $TEMP_FILE
14
+
15
+ # Iterate over each log file provided as a positional parameter
16
+ for LOG_FILE in " $@ " ; do
17
+ # Check if the file exists
18
+ if [ ! -f " $LOG_FILE " ]; then
19
+ echo " File not found: $LOG_FILE "
20
+ continue
21
+ fi
22
+
23
+ # Extract lines with command=, get the hour from the timestamp, and append to the temporary file
24
+ grep ' command=' " $LOG_FILE " | awk ' {print substr($1 " " $2, 1, 13)}' >> $TEMP_FILE
25
+ done
26
+
27
+ # Sort the combined results and count occurrences per hour
28
+ sort $TEMP_FILE | uniq -c > hourly_counts.txt
29
+
30
+ # Display the results
31
+ cat hourly_counts.txt
32
+
33
+ # Clean up
34
+ rm $TEMP_FILE
35
+ rm hourly_counts.txt
You can’t perform that action at this time.
0 commit comments