fixed APN to fetch the third field directly

This commit is contained in:
dr-dolomite
2024-03-18 09:47:38 +08:00
parent 19a10334cb
commit 7007844977
3 changed files with 14 additions and 7 deletions

View File

@@ -62,8 +62,7 @@ MODEM_MODEL=$(</tmp/modemmodel.txt)
MODEM_MODEL=$(echo "$MODEM_MODEL" | grep -o "RG[^ ]\+\|RM[^ ]\+")
# Get the APN from /tmp/apn.txt and parse it
APN=$(</tmp/apn.txt)
APN=$(echo "$APN" | grep -o '"[^"]*"' | head -n1 | tr -d '"')
APN=$(grep "^+CGCONTRDP" /tmp/apn.txt | awk -F',' '{gsub(/"/, "", $3); print $3}')
# Get the SIM slot from /tmp/simslot.txt and parse it
# simslot.txt looks like this: +QUIMSLOT: 1

View File

View File

@@ -8,6 +8,7 @@ file_name="$1"
echo "{"
last_line=$(wc -l < "$file_name")
first_line=true
while IFS='=' read -r key value || [[ -n "$key" ]]; do
# Skip empty lines and comments
@@ -26,15 +27,22 @@ while IFS='=' read -r key value || [[ -n "$key" ]]; do
value="\"$value\""
fi
# Print key-value pair in JSON format without surrounding double quotes on value
printf ' "%s" : %s' "$key" "$value"
# Check if value is empty, if so, skip printing this key-value pair
if [[ -z "$value" ]]; then
continue
fi
# Check if not the last line, add comma
if [ $((++current_line)) -lt "$last_line" ]; then
# Print comma before each pair except for the first one
if $first_line; then
first_line=false
else
printf ','
fi
# Print key-value pair in JSON format without surrounding double quotes on value
printf ' "%s" : %s' "$key" "$value"
printf '\n'
done < "$file_name"
echo "}"
echo "}"