Я использую этот пакет:
1 .https://github.com/openwrt/packages/blo ... /README.md
Эй, я пытаюсь зарегистрировать общее количество «заблокированных " запросы в файле json, например
это:
Код: Выделить всё
{
"TOTAL": 39100,
"BLOCKED": 16172
}
Но когда я обновляю отчет для создания текущего сообщите о файле json,
изменены значения start_timestamp и end_timestamp (не знаю, как и когда они изменяются), поэтому я не могу вычислить фактические
общие числа.
* * мой код приложен ниже.**
Код: Выделить всё
#!/bin/bash
# Path to the JSON file
JSON_S_FILE="adb_report.json"
# Path to extracted datd file
JSON_O_FILE="stored_data.json"
# Check if the JSON file exists
if [ ! -f "$JSON_S_FILE" ]; then
echo "Error: JSON file '$JSON_S_FILE' not found!"
exit 1
fi
# Extract specific values using jq
TOTAL=$(jq -r '.total' "$JSON_S_FILE")
BLOCKED=$(jq -r '.blocked' "$JSON_S_FILE")
#updating values in extracted data file
if [ -s $JSON_O_FILE ] && jq empty $JSON_O_FILE >/dev/null 2>&1; then
#if exists & valid
echo "The JSON file is valid and not empty."
jq --arg total "$TOTAL" --arg blocked "$BLOCKED" \
'{"TOTAL": ((.TOTAL|tonumber) + ($total|tonumber)),
"BLOCKED": ((.BLOCKED|tonumber) + ($blocked|tonumber))}' \
"$JSON_O_FILE" > temp.json && mv temp.json "$JSON_O_FILE"
else
#if not, create & write!!
echo "The JSON file is either empty or not valid."
echo "{\"TOTAL\": \"$TOTAL\", \"BLOCKED\": \"$BLOCKED\"}" >stored_data.json
fi
Пример Json выглядит следующим образом:
Код: Выделить всё
"start_date": "2024-12-24",
"start_time": "22:13:12",
"end_date": "2024-12-25",
"end_time": "01:05:04",
"total": "6076",
"blocked": "4355",
"percent": "71.68%",
спасибо!
Подробнее здесь: https://stackoverflow.com/questions/793 ... statistics