Randomly getting "NO CARRIER" from Huawei 3G modem under linux

Ok, I think what's happening is the modem gets confused when wvdial starts talking to it before it's finished registering.

-> Added a 2s delay after plugging in the device, and have the script wait until the device is registered before running wvdial. Then it always works !!

#!/bin/bash
while [ -e /dev/ttyUSB0 ] ; do
  # wait to be registered
  if ./operator | grep -q ','; then
    wvdial provider >> wvdial.log 2>&1
  fi
  sleep 1
done

operator script:

#!/bin/bash
# boy, is this ugly ...
chat -t 1 -e "" '\pAT' OK AT+COPS? +COPS '\pAT' OK >> /dev/ttyUSB1 < /dev/ttyUSB1 2>/tmp/foo
grep -m 1 '^+COPS' /tmp/foo