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

View File

View File

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