forked from mendersoftware/mender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmender-inventory-intervals
executable file
·46 lines (39 loc) · 1.33 KB
/
mender-inventory-intervals
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
#!/bin/sh
json_file="/etc/mender/mender.conf"
if [ ! -f "$json_file" ]; then
echo "File not found: $json_file" >&2
exit 1
fi
to_kebab_case() {
string="$1"
# Remove the word "interval"
string=$(echo "$string" | sed 's/Interval//g')
# Replace capital letters with hyphen-lowercase
string=$(echo "$string" | sed 's/\([A-Z]\)/-\1/g')
# Convert to lowercase
string=$(echo "$string" | tr '[:upper:]' '[:lower:]')
# Preppend the "interval" word
string=$(echo "$string" | sed -E 's/^/interval/g')
echo "$string"
}
extract_and_print() {
key="$1"
line="$2"
if echo "$line" | grep -q "\"$key\""; then
value=$(echo "$line" | sed -E 's/.*"'$key'":\s*([^,}]+).*/\1/')
value=$(echo "$value" | sed -E 's/^"|"$//g')
key=$(to_kebab_case "$key")
printf "%s=%s\n" "$key" "$value"
fi
}
# Read the JSON file line by line
while IFS= read -r line; do
# Extract and print InventoryPollIntervalSeconds
extract_and_print "InventoryPollIntervalSeconds" "$line"
# Extract and print RetryPollIntervalSeconds
extract_and_print "RetryPollIntervalSeconds" "$line"
# Extract and print UpdatePollIntervalSeconds
extract_and_print "UpdatePollIntervalSeconds" "$line"
# Extract and print RetryPollCount
extract_and_print "RetryPollCount" "$line"
done < "$json_file"