ModemManager Hotplug script: Request for review

This hotplug script is intended to work with ModemManager connections to keep the modem connection up and running. Sometimes ModemManager will think the modem is connected even though the data session is inactive. I don't have a full understanding, but I surmise it is basically because the object referencing the previous state of the modem (bearers, modem, etc) has gone stale. The way I'm working around this is to just restart the ModemManager service and bring the iface back up.

One problem at the moment is if you disable/stop the modem interface it will be restarted by the hotplug script. Is there a hotplug event that could be used to not fire the script in that case? Or Perhaps just reference a UCI configuration element?

Currently it only works with ModemManager 1.8, but work on updating it to 1.10 should start soon.

Refactored

1 Like
  1. Useless use of cat:
cat FILE | grep PATTERN

grep PATTERN FILE
  1. Deadline for ping is mandatory:
ping ...

ping -w 30 ...
  1. Extract large command blocks:
if EXPR; then
    LARGE_BLOCK_OF_COMMANDS
fi
EOF

if ! EXPR; then
    exit
fi
LARGE_BLOCK_OF_COMMANDS
EOF
1 Like

Thank you for the suggestions. It makes sense

  1. Use grep only, so it just uses one command
  2. So we put a maximum running time on that command
  3. To exit early to save some CPU cycles
1 Like