-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathib_fw_warn.sh
More file actions
executable file
·133 lines (113 loc) · 4.03 KB
/
ib_fw_warn.sh
File metadata and controls
executable file
·133 lines (113 loc) · 4.03 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
set -euo pipefail
# Path to the generated file
# file_path and lookup_file default to the same ibdiagnet CSV but can be
# overridden independently (e.g., warnings from one run, node names from another).
file_path="/var/tmp/ibdiagnet2/ibdiagnet2.db_csv"
lookup_file="/var/tmp/ibdiagnet2/ibdiagnet2.db_csv"
# Output file where results will be stored
my_name=$(basename "$0" | awk -F. '{print $1}')
output_file="${my_name}.csv"
# Function to display help
show_help() {
echo ""
echo "Usage: ${my_name}.sh [options]"
echo "Options:"
echo " -h, --help Show this help message and exit"
echo " -f <file> Specify input file path (default: $file_path)"
echo " -l <lookup_file> Specify lookup file path (default: $lookup_file)"
echo " -o <output_file> Specify output file path (default: $output_file)"
echo ""
echo "${my_name}.sh looks up WARNINGS_FW_CHECK section in ibdiagnet2.db_csv "
echo "and replaces GUIDs with Node names from the NODES section."
echo "Output is saved in CSV format with columns: column_2 (Node name), column_6 (summary)"
}
# Parse command line options
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
show_help
exit 0
;;
-f)
file_path="$2"
shift 2
;;
-l)
lookup_file="$2"
shift 2
;;
-o)
output_file="$2"
shift 2
;;
*)
echo "Unknown option: $1"
show_help
exit 1
;;
esac
done
# Check if the file exists
if [ ! -f "$file_path" ]; then
echo "Error: $file_path does not exist. Exiting."
exit 1
fi
# Write CSV header
echo "column_2,column_6" > "$output_file"
# Flag to track when we are between START_WARNINGS_FW_CHECK and END_WARNINGS_FW_CHECK
processing=false
# Read the lookup file into a hash table (associative array) for fast lookups
declare -A lookup_table
# Flag to process nodes from START_NODES to END_NODES
in_nodes_section=false
# Read the lookup file line by line and populate the lookup table
while IFS= read -r line; do
# Skip lines until we find the START_NODES section
if [[ "$line" == *"START_NODES"* ]]; then
in_nodes_section=true
continue
fi
# Stop processing when we reach END_NODES
if [[ "$line" == *"END_NODES"* ]]; then
in_nodes_section=false
continue
fi
# If we are in the node section, process the line
if $in_nodes_section; then
# Extract column 1 (Node name) and column 6 (GUID) using IFS splitting
IFS=',' read -r column_1 _ _ _ _ column_6 _ <<< "$line"
# Add the GUID (column 6) as the key and node name (column 1) as the value to the lookup table
lookup_table["$column_6"]=$column_1
fi
done < "$lookup_file"
# Flag to track when we are between START_WARNINGS_FW_CHECK and END_WARNINGS_FW_CHECK
processing=false
# Read the target file line by line
while IFS= read -r line; do
# Check if we are starting to process
if [[ "$line" == *"START_WARNINGS_FW_CHECK"* ]]; then
processing=true
continue
fi
# Check if we have reached the end of the processing section
if [[ "$line" == *"END_WARNINGS_FW_CHECK"* ]]; then
processing=false
continue
fi
# If we are between the start and end markers
if $processing; then
# Split the line by commas and extract column 2 (GUID) and column 6 (summary)
IFS=',' read -r _ column_2 _ _ _ column_6 _ <<< "$line"
# Remove the '0x' prefix from column 2 (if it exists)
column_2="${column_2#0x}"
# Look up the column_2 value (GUID) in the lookup table and replace with column_1 (Node name)
if [[ -n "${lookup_table[$column_2]+x}" ]]; then
column_2="${lookup_table[$column_2]}"
fi
# Write the extracted and modified information to the output file
echo "$column_2,$column_6" >> "$output_file"
fi
done < "$file_path"
# Display the results
echo "Wrote: $output_file"