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
mmcli
sees the modem (I have been trying to get this to work, but calls to thesleep
function are skipped, and it won't let me run in a different thread) - Run script automatically when
mmcli
recognizes 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}"
mmcli -L
inside the script before the connection part? Something like:while :;do mmcli -L|grep -q modem_name&&break;sleep 1;done
– Or how about using the-w
option to “Monitor the state of a given modem”, one could parse its output and act on that. – dessert Apr 23 '19 at 19:57