USB modem: Autodialer script for linux

I am using Tata Indicom’s “Plug to Surf” USB Modem for my laptop. Its handy and gives a better speed so I also suggest this to my friends as well. I have given a Ubuntu Desktop for many of my non-techie friends and dialing using wvdial and keeping the terminal open looks mess to them. I wanted them to enjoy Plug and Play features and hence I worked on this.

Plug your USB Modem to your laptop/PC just wait for a few minutes and your are ready to surf the net. Pretty interesting, huh?

Well the recipe is given below.
1. I assume you have Tata Indicom’s “Plug to Surf” USB Modem duly configured on your Linux machines.
2. If your are not able to figure out how to do that just read the bundled CD carefully, its pretty well mentioned on it.

So, first things first. What files will you need to touch?
i. /usr/bin/wvdial
ii. a new file may be /etc/udev/rules.d/85-autodial-usb-modem.rules

Change permissions of your wvdial so that any user can run that as root. Sounds security violation but thats okay if you are a single user on laptop or desktop.
ameya@ameya-laptop:~$ sudo chmod a+s /usr/bin/wvdial
ameya@ameya-laptop:~$ ls -l /usr/bin/wvdial
-rwsr-sr-x 1 root 0 76220 2007-03-09 03:23 /usr/bin/wvdial

Now you need to know the USB device ID of your modem.

ameya@ameya-laptop:~$ lsusb
Bus 004 Device 001: ID 0000:0000
Bus 003 Device 001: ID 0000:0000
Bus 002 Device 001: ID 0000:0000
Bus 001 Device 016: ID 1b7d:070a
Bus 001 Device 001: ID 0000:0000

Notice that Bus 001 is shoing ID as 1b7d:070a
Here the first number before a ( : ) is the vendor id and later is the Product id. Now its time to tell your UDEV service about it. Create a new file sumthing like this.

ameya@ameya-laptop:~$ sudo vi /etc/udev/rules.d/85-autodial-usb-modem.rules

Now insert the below line in this rules file and save and close.

ACTION==”add”, SUBSYSTEM==”usb_device”, SYSFS{idVendor}==”1b7d”, SYSFS{idProduct}==”070a”, OWNER=”ameya”,RUN+=”/usr/bin/wvdial”

Make sure to change the idVendor and idProduct values as per your USB Vendor ID.

ameya@ameya-laptop:~$ sudo chmod 644 /etc/udev/rules.d/85-autodial-usb-modem.rules
ameya@ameya-laptop:~$ ls -l /etc/udev/rules.d/85-autodial-usb-modem.rules
-rw-r–r– 1 root 0 128 2008-06-08 18:46 /etc/udev/rules.d/85-autodial-usb-modem.rules

Now restart the UDEV services.
ameya@ameya-laptop:~$ /etc/init.d/udev restart

This is it. Now whenever you connect your USB modem to the port just wait for a minute and it then you are ready to surf the internet. You will not need to dial any services. Now, I have noticed that when you connect the USB Modem it first gives you a red light indication which means that Modem is searching for Network Range. When it turns to green it is actually ready to dial. At this time our script is dialling the modem. Once it is done it will give you blinking green signal which means it is sending/receiving the packets meaning you can now surf the web.

Well, now that its auto-dialling there should be some easy way to terminate the modem. Here it is.
We only need to create 1 file as below.
ameya@ameya-laptop:~$ vi byebye

Insert the below line to it and save and close.

kill -9 `ps aux |grep wvdial |grep -v grep | awk ‘{print $2}’`

Now, make the file executable with,

ameya@ameya-laptop:~$ chmod 755 byebye
ameya@ameya-laptop:~$ ls -l byebye
-rwxr-xr-x 1 root 0 63 2008-06-08 10:25 /home/ameya/byebye

Copy the file to your bin directory.

ameya@ameya-laptop:~$ sudo cp byebye /usr/bin/

How to use this file?
When you are connected to the net and wish to disconnect just go to the terminal and run the below command.
ameya@ameya-laptop:~$ sudo byebye

It will ask the user password to disconnect. Isn’t it easy?
Or you can copy the file on your desktop so that you can double click the executable to disconnect.

ameya@ameya-laptop:~$ sudo cp byebye /home/ameya/Desktop/

Now, double click on the file and open in a terminal.. provide password to disconnect the internet.
Do let me know if it finds useful to you.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>