From 24f8ed84780d2cac47aa121618f9d7bc30772479 Mon Sep 17 00:00:00 2001 From: Maarten van Gompel Date: Sat, 30 Jan 2021 18:17:46 +0100 Subject: [PATCH] wait for modem for a bit when it is not immediately available yet (e.g. after crust wakeup) --- scripts/modem/sxmo_modemmonitor.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/modem/sxmo_modemmonitor.sh b/scripts/modem/sxmo_modemmonitor.sh index 5b1d239..dcc0913 100755 --- a/scripts/modem/sxmo_modemmonitor.sh +++ b/scripts/modem/sxmo_modemmonitor.sh @@ -16,9 +16,19 @@ gracefulexit() { } modem_n() { - MODEMS="$(mmcli -L)" - echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' > /dev/null || err "Couldn't find modem - is your modem enabled?\nDisabling modem monitor" - echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2 + TRIES=0 + while [ "$TRIES" -lt 10 ]; do + MODEMS="$(mmcli -L)" + if ! echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' > /dev/null; then + TRIES=$((TRIES+1)) + echo "sxmo_modemmonitor: modem not found, waiting for modem... (try #$TRIES)">&2 + sleep 1 + else + echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2 + return + fi + done + err "Couldn't find modem - is your modem enabled? Disabling modem monitor" } lookupnumberfromcallid() {