I need to run a script that will create a connection when modem manager detects a modem (ie. mmcli -L lists the modem). I currently have a udev rule set up to do this, but mmcli takes so long to register the modem that the script has already finished running.
I am hoping there is a way to do one of the following things:
- Delay the start of the script from udev
- Allow the script to run in the background or go to sleep until
mmclisees the modem (I have been trying to get this to work, but calls to thesleepfunction are skipped, and it won't let me run in a different thread) - Run script automatically when
mmclirecognizes the modem
Here is a snippet of my most recent attempt:
sleep 10
count=0
while [ count < 300 ]
do
index=$(mmcli -L | grep Modem | head -n1 | awk '{print $1;}')
let "count+=1"
done
port=$(mmcli -m $index | grep 'primary port' | grep -oP 'ttyACM[0-9]')
connection=$(nmcli c show | grep "modem${port: -1}")
# check if connection does not exist
if [ ! $connection ]; then
echo 'adding new connection at ' date >> /home/nvidia/runlog.txt
nmcli c add type gsm ifname "${port}" con-name "modem${port: -1}" apn testers.apn.com
fi
nmcli c up "modem${port: -1}"