Sunday, August 22, 2010

How I read the balance information from a 3G/GPRS data connection

For last few months I am using BSNL 3G internet connection. I am using a prepaid connection through USB 3G device. So, before and after every internet session I need to know the remaining balance of my sim card, but the device have no LCD screen/keypad. That is why every time I have to insert the sim card into a mobile to get the balance of the sim card.

Recently I have solve this problem. I have wrote a python code to get the balance of the sim card directly through USB 3G device. I have wrote a supporting shell script also to create GUI interface for that python code.

The only dependencies to run the code are Python and Zenity.

I have wrote the code for my BSNL 3G connection, and have to customise for other connection.
import sys
import serial
serial_device = serial.Serial(sys.argv[1],timeout=8)
except IndexError:
print "\nMobile Balance\n\nSyntax: /dev/ttyUSB[2..5]\n"
except serial.serialutil.SerialException:
print "\nUnable to open port",sys.argv[1],"\n"
while (1):
text_output = serial_device.readline()
if text_output.find('+CUSD')==0:
text_output = text_output.lstrip('+CUSD: 0,"')
print text_output.rstrip('",15\r\n')

PreviousBalance=`cat /tmp/mobile_balance.tmp`
python `echo $0 | sed 's/.sh/.py'/` `ls /dev/ttyUSB{2..5} 2>/dev/null` > /tmp/mobile_balance.tmp | zenity --info --text="Mobile balance calculation in progress\nClick 'OK' and\nWait for a while....."
echo -e "Current Balance\n"`cat /tmp/mobile_balance.tmp` "\n\nPrevious Balance..\n" $PreviousBalance | zenity --text-info --title="Mobile Balance" --width=250 --height=300


Friday, May 7, 2010

How an administrator can unlock a table to overcome deadlock situation in MySQL

This is a common problem for a MYSQL DBA if the application has table lock bug. To unlock a table I use session kiil procedure. The steps are....

Step 1: login into mysql user root user.
Step 2: list all the sessions running in MySQL server.

show processlist;

The output will be looks like....

| Id | User | Host | db | Command | Time | State | Info | +-----+----------+-----------+------+---------+------+-------+------------------+
| 349 | his_user | localhost | NULL | Query | 0 | NULL | show processlist | +-----+----------+-----------+------+---------+------+-------+------------------

...if the MySQL server has no other running process. Otherwise the output will show other process id also. For locked processes the status will indicate the work lock.

Step 3: The last step is to kill the locked running process using process Id.

kill xxx;

'xxx' is the process Id value.

Monday, May 3, 2010

How to reset MySQL root password

These steps are required if we have lost(for my case) the root password for MySQL administration.

Step 1: At first I stop the MySQL service from Linux root user.

/etc/init.d/mysql stop

Step 2: Then I start again MySQL service with --skip-grant-tables, so that at the time of login into the MySQL service system should not ask for authentication.

mysqld_safe --skip-grant-tables &

Step 3: In this step I first login into MySQL root user without password.

mysql -u root

Then I issue the following MySQL command to change the root password and quit to Linux shell..

use mysql;
update user set password=password('password') where user='root';
flush privileges;

Step 4: The last stage is to restart MySQL server using default option.

/etc/init.d/mysql restart

The password for root user is changed now. I have done all these procedures on the OS Debuan 5.

Wednesday, April 28, 2010

How I connect internet using my bluetooth enabled mobile(GPRS) phone

Initially I starts searching the device of my mobile phone, after traversing the menu of mobile phone I have found the device id 00:0d:92:31:66:0d.

In next stage I have bound the device id with the named device /dev/rfcomm0 using the command rfcomm

The command I have issued is....

rfcomm bind /dev/rfcomm0 00:0d:92:31:66:0d

In the third or last stage I have change the value of Modem directive in /etc/wvdial.conf file.

Modem = /dev/rfcomm0

New my job is complete. After these steps now I can connect internet using wvdial through bluetooth enabled mobile phone.