Artificial Thinking

Everything That Interests Me

Starting/Stopping Mobile Broadband Services in Linux

with one comment

I am using Fedora for years now and ever since I had a curiosity to know how this Mobile Broadband works in Linux. I need to start and stop it via terminal rather than doing it using gnome network manager.

First thing you have to do is connect your broadband device and configure a connection via the prompted wizard. Once this is done, you need to know 2 things about this connection which you just created. Execute the following command in the terminal.

nmcli -p con

This will list down all the connections in your system. Following is sample output, where I have only grepped gsm type connection for this blog purpose.

================================================================
Connection list
================================================================
NAME                                    UUID                                                     TYPE
—————————————————————————————————————-
Dialog GSM Postpaid         hjhu515c-dheyd-hjgu-a139-669a1d28304a      gsm

Here the name of the connection (aka id) and UUID are what you really need. Set these 2 variables with your Connection Name (id) and UUID in the following shell script.

defaultConnection=”Dialog GSM Postpaid”
defaultConnectionsUUID=daad515c-b1e7-4a5c-a139-669a1d28304a

Once you set those 2 variables in the following shell script snippets, save it as mobile-broadband.sh and set it to the executable mode.

chmod +x  mobile-broadband.sh

Now try following 4 commands.

  • ./mobile-broadband.sh start
  • ./mobile-broadband.sh stop
  • ./mobile-broadband.sh status
  • ./mobile-broadband.sh

Shell Script (Save the following to new mobile-broadband.sh file)

# SCRIPT BEBINGS FROM HERE
#!/bin/bash

# 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=daad515c-b1e7-4a5c-a139-669a1d28304a

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 is 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 “”
echo “IMPORTANT!”
echo “Edit this script to replace the values for defaultConnection and defaultConnectionsUUID with your gsm connection details”
echo “We found the following Connections list (ONLY GSM TYPE) for your system”
echo ==================================
echo Connection list
echo ==================================
echo ID UUID TYPE
echo ———————————-
nmcli -p -f NAME,UUID,TYPE con | grep gsm
exit 1

esac
exit 0

# SCRIPT ENDS HERE

Advertisements

Written by azeemigi

June 13, 2012 at 2:53 PM

Posted in Software

Tagged with , , , ,

One Response

Subscribe to comments with RSS.

  1. […] how do you connect with a dongle when you don’t have a GUI? azeemigi’s blog has the solution. I’m reproducing it here just for the sake of my own future […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: