Skip to content

Instantly share code, notes, and snippets.

@thameera
Created October 8, 2013 17:12
Show Gist options
  • Save thameera/6888050 to your computer and use it in GitHub Desktop.
Save thameera/6888050 to your computer and use it in GitHub Desktop.
Connect to mobile broadband via terminal
#!/bin/bash
# Source: http://aithinking.wordpress.com/2012/06/13/startingstopping-mobile-broadband-services-in-linux/
# To get the connection name (id) and connection uuid, execute the following command
# nmcli -p con
# Replace defaultConnection and defaultConnectionsUUID with your own settings
defaultConnection="Dialog GSM Postpaid"
defaultConnectionsUUID=bb06d9f7-772c-4b4b-851a-4564503c3798
interval=2
case "$1" in
start)
echo "Starting the mobile broadband connection: " $defaultConnection " (UUID - " $defaultConnectionsUUID ")"
while true; do
LC_ALL=C nmcli -t -f TYPE,STATE dev | grep -q "^gsm:disconnected$"
if [ $? -eq 0 ]; then
echo "Device found: " $defaultConnection
break
else
echo "Device not found. Retrying in " $interval " seconds."
sleep $interval
fi
done
echo "Starting Wireless WAN"
nmcli -t nm wwan on
echo "Connecting " $defaultConnection
nmcli -t con up uuid $defaultConnectionsUUID
echo "Successfully connected"
;;
stop)
echo "Stopping the mobile broadband connection: " $defaultConnection " (UUID - " $defaultConnectionsUUID ")"
nmcli -t con down uuid $defaultConnectionsUUID
echo "Stopping Wireless WAN"
nmcli -t nm wwan off
echo "Successfully disconnected"
;;
status)
LC_ALL=C nmcli -t -f TYPE,STATE dev | grep -q "^gsm:disconnected$"
if [ $? -eq 0 ]; then
echo "Device not found or GSM disconnected"
else
echo "GSM connected"
fi
;;
*)
echo "Mobile Broadband startup service"
echo $"Usage: $0 {start|stop|status"
echo ""
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment