How to auto connect Ubuntu 12.04 USB GSM Mobile Broadband Connection on Boot as startup service without user login using Network Manager CLi

This guide is intended as a relatively easy step by step guide to:

  • Create a auto start bash script to start the mobile broadband connection at boot time as a startup service without needing to log in as a user.
  • * Update: Added version 2 of the script that will also auto re-connect the mobile broadband connection if the connection is dropped, disconnected or lost for some reason.

Requirements:

  • Ubuntu 12.04 LTS machine with a USB GSM 3G Modem

1. Setup a new Mobile Broadband Connection and connect.

  • After you have set up a new Mobile Broadband Connection it will appear in the network connections (click on taskbar network icon).
  • In this case our new connection name is : 8ta 
  • Connection 'name' should contain only alpha-numerical characters and no spaces to avoid problems.
  • Make sure the "Enable Mobile Broadband" is activated. (see below)
  • Connect to the internet with your Mobile Broadband connection by clicking on the connection name. In this case 8ta

2. Create a Network Manager CLi startup script for your connection.

  • Open the Terminal Window and enter :
sudo gedit /etc/init.d/mobile-broadband-connect
  • Add the following into the startup script file and save: 
  • Note: Replace the YourMobileBroadbandConnectionNameHere with the name of your connection. In this case our service provider is: 8ta
  • Note: If you want the script to also auto re-connect the connection if lost rather use version 2.
  • Note: If you do not see a codeblock right below this text or see a small empty box before step 3 - please reload this page.

​3. Change the startup script file permissions.

  • By default a new file is not allowed to be executed - so we need to modify the permissions to allow us to run the script at startup..
  • Open the Terminal Window and enter :
sudo chmod +x /etc/init.d/mobile-broadband-connect

​4. Update system startup defaults to include your new script as a service.

  • To update the startup services, open the Terminal Window and enter :
sudo update-rc.d mobile-broadband-connect defaults
  • The script is registered as a system startup service so you can start, stop, or check the status of the script with :
sudo service mobile-broadband-connect start
sudo service mobile-broadband-connect stop
sudo service mobile-broadband-connect status

​5. Reboot to complete installation and auto connect.

  • Reboot your system to complete the installation.
  • After reboot it takes up to 60 seconds before the USB device is active.
  • When active - The Mobile Broadband Connection will be activated and auto connected.

6. Troubleshooting.

  • If it does not connect on startup the most likely problem is that the connection is not available to all users at startup.
  • Click on "Edit Connections..." in the Network Connections Manager dialog window, select Mobile Broadband, select your connection, and click on "Edit".
  • Make sure that the "Available to all users" is selected and click on Save

 

Version 2: How to Auto Re-Connect the Mobile Broadband Connection.

  • The script in step 2 is only to establish a connection once the GSM modem becomes available on the system, usually during boot, but can also be in the form of a USB modem that is plugged into the computer.
  • If the connection is dropped for whatever reason the script does not automatically re-connect the modem.
  • The script was updated in version 2 below to allow for this event. It will keep running in the backgroud and keep trying to establish a GSM connection if it finds the modem disconnected for some reason.
  • Edit the script file created in step 2, by opening a terminal window and entering:
sudo gedit /etc/init.d/mobile-broadband-connect
  • Then replace the original code with the code below and save: 
  • Note: Replace the YourMobileBroadbandConnectionNameHere with the name of your connection. In this case our service provider is: 8ta

Download: 

Tags: 

Comments

AT last and you beauty!

AT last and you beauty! Thanks to all concerned, I've been trying to do this off and on for MONTHS. While not a unix guru I am a PC guru and have struggled with this one... Most of my problem is plain bad attitude: WHY? when the "Connect Automatically" option is checked does it NOT connect automatically without need for a separate script like this one!?!, etc etc etc. So thanks again for this, I'll try not to be so pig headed in the future.

Add new comment