07 October 2013

Updating Linux Kernel

updating kernel

how to update ubuntu kernel to 3.10

The current long term linux kernel is 3.10 (correct as of 2013). so it's a good choice for previous longterm kernel user to jump to 3.10 for it bring many new features and improvement.
    Advantages of longterm kernel 3.10 are:

  • Tickless Timer
    Improve CPU performance and latency by reducing tick from 1000 to 1 per second.
  • Tail loss probe
    Improve network latency.
  • Bcache
    HDD performance improvement, by allowing SSD to act as cache.
  • ARM big.LITTLE support
  • MIPS KVM support
  • Memory, filesystem, Networking, crypto, Security, Virtualization Improvement
  • and many more...

Installing the latest kernel

# download the latest kernel in 'deb' format from kernel.ubuntu.com :

for 32-bit system
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.10.14-saucy/linux-headers-3.10.14-031014_3.10.14-031014.201310011335_all.deb
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.10.14-saucy/linux-headers-3.10.14-031014-generic_3.10.14-031014.201310011335_i386.deb
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.10.14-saucy/linux-image-3.10.14-031014-generic_3.10.14-031014.201310011335_i386.deb

for 64-bit system
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.10.14-saucy/linux-headers-3.10.14-031014_3.10.14-031014.201310011335_all.deb
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.10.14-saucy/linux-headers-3.10.14-031014-generic_3.10.14-031014.201310011335_amd64.deb
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.10.14-saucy/linux-image-3.10.14-031014-generic_3.10.14-031014.201310011335_amd64.deb

# install by running:
sudo dpkg -i *.deb

See The Changes

Unfortunately, you will have to reboot your computer to see the changes. the new kernel shall be visible in GRUB menu during bootup. Generally, GNU/Linux does never need to reboot for software, library etc et al to work after install. But kernel will be an exception.

# in rare case if it does not appear or update the grub menu itself:
sudo update-grub

note: this method will work on ubuntu and its derivatives.

28 September 2013

An Intro on SQLite

SQLite is a Relational Database Management System (RDMS). but unlike other RDMS, it does not require a ceentral server to be run or client to access the process. and lightweight. due to its small size it is use in various application, Operating System, Embedded System etc. The best part of it, it is in Public Domain. Which mean any software maker, individual or software company can use and impliment it into their application. SQLite is use in various open source and closed source system.

SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.
      - sqlite.org

    SQLite is use in various software appication:
  • Mozilla Firefox
  • Google Chrome
  • Opera
  • Ruby On Rails
  • Adobe System
  • and more..
    SQLite is also use in various OS:
  • NetBSD
  • OpenBSD
  • Apple iOS
  • Google Android
  • Windows Phone 8
  • Symbian OS
  • BlackBerry 10 OS
  • and more..
Despite it small size, it implement almost all SQL standard query. but few features are missing, like 'ALTER TABLE'.

A short tutorial

# Checking SQLite version:
sqlite3 -version
-- Loading resources from /home/user/.sqliterc

3.7.15.2 2013-01-09 11:53:05 c0e09560d26f0a6456be9dd3447f5311eb4f238f

# Getting Usage help:
sqlite3 -help

# Create a database 'foo.db' :
sqlite3 foo.db
This will create the foo.db (empty database) and drop to sqlite shell.
SQLite version 3.7.15.2 2013-01-09 11:53:05
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>

# To create a table, we will run an SQL query:
sqlite> CREATE TABLE person (name VARCHAR(12), age VARCHAR(3));
a table 'person' will be created with column name & age.

# Display all tables in the database:
sqlite> .tables
Or similar tables..
sqlite> .tables ??TABLE??

# Adding data to table:
sqlite> INSERT INTO person VALUES ('jack', '50');
sqlite> INSERT INTO person ('name') VALUES ('henry');

# Displaying the inserted data:
sqlite> SELECT * FROM person;

SQLite can also read SQL query from a text file.

sql.txt
select * from person;
select * from person where name='john';

# To run SQL query that is given in sql.txt .
sqlite> .read sql.txt

To manipulate any data in the databases the user will have to run SQL query. This author guess that the reader has prior knowledge of SQL query.

# To exit SQLite shell:
sqlite> .quit
sqlite> .exit


23 September 2013

Making USB Modem work in GNU/Linux

the short way

Short tutorial for those who donot have all the time in the world to read a lengthy tutorial.
Open ' Terminal ' and run..
eject /dev/sr1
lsusb
Bus 001 Device 004: ID 24e3:3e76 3G Modem
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Note the ID corresponding to USB/3G Modem.
sudo modprobe usbserial vendor=0x24e3 product=0x3e76


the long way

This tutorial will work for most 2G, 3G, 4G or any USB Modem under GNU/Linux using debian/ubuntu.

# Before inserting your usb modem. Open 'Terminal' and run the following command:
ls /dev/sr*
It'll output something like:
/dev/sr0
sr0 is mostly CD/DVD-Drive or any Serial Drive connected.

# Now insert your USB Modem and run the command again..
ls /dev/sr*
/dev/sr0 /dev/sr1
Note the extra serial device (sr1). it is your usb modem internal storage, because when attached they are dectcted as storage devices. It's explained in 'man usb_modeswitch'.
...When plugged in for the first time, they act like a flash storage and start installing the Windows driver from there. If the driver is already installed, it makes the storage device disappear and a new device, mainly composite with modem ports, shows up.

On Linux, in most cases the drivers are available as kernel modules, such as "usbserial" or "option". However, the device shows up as "usb-storage" by default...


# In 'Terminal':
lsusb
Bus 001 Device 004: ID 24e3:2205 3G Modem
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
note the ID corresponding your USB 3G Modem.

# Eject the modem storage:
eject /dev/sr1
..and..
lsusb
Bus 001 Device 004: ID 24e3:3e76 3G Modem
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
It will show a new ID for the Modem.
24e3:3e76
24e3 is VendorID. 3e76 is ProductID of the modem.

# Make the modem visible to the system by running modprobe:
sudo modprobe usbserial vendor=0x24e3 product=0x3e76
Replace the ID with your Modem ID.

Wait a minute for the modem to appear in Network Manager.


04 May 2013

Screw yourself with IFCONFIG



If you does not know what in the world is  ifconfig !    SCREW YOURSELF!   for your kind information  ifconfig  is a network interface configuration tool.

Open Terminal:
ifconfig
For  Windows, command will be slightly different:
ipconfig
Output:
eth0      Link encap:Ethernet  HWaddr 00:1d:60:06:cc:2d  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:852 errors:0 dropped:0 overruns:0 frame:0
          TX packets:852 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:64720 (64.7 KB)  TX bytes:64720 (64.7 KB)

Show all interfaces:
ifconfig -a

Display information for eth0 interface:
ifconfig eth0


The fun begin..

Take down the eth0 interface:
ifconfig eth0 down
This will deactivate eth0.

Change the IP address of eth0:
ifconfig eth0 111.111.0.0

Change the hardware address of eth0:
ifconfig eth0 hw ether aa:aa:aa:aa:aa:aa

Bring up the interface eth0:
ifconfig eth0 up

Now run ifconfig..
ifconfig eth0
Output:
eth0      Link encap:Ethernet  HWaddr aa:aa:aa:aa:aa
          inet addr:111.111.0.0  Bcast:255.255.255.255  Mask:0.0.0.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

These are few example of ifconfig. more option and argument can be found in man page.
man ifconfig


27 April 2013

more SQL tutorial



Let us build a database  'test' with table  'person' inside it, having column  name, age, gender. see how to do this


Insert a line into table:
INSERT INTO person (name, gender) VALUES ('omphu', 'female')
This will add a new line or data into the table  'person' on column  name, gender with value omphu, female respectively and will leave the value of age blank.

Select line using WHERE:
SELECT * FROM person WHERE gender='female'

Select specific column:
SELECT name FROM person WHERE gender='male'
This will output the value of column name where gender is female.

Specify more argument to refine search:
SELECT name, age FROM person WHERE age='21' AND gender='male'
Will output result if this two condition are true,  age & gender.

SELECT name, age FROM person where age='21' OR gender='female'
This will output result if one of the two condition is true,  age & gender.

Limit output to 5 result:
SELECT * FROM person LIMIT 5

Sort result by Ascending/Descending order:
SELECT * FROM person ORDER BY name ASC
SELECT * FROM person ORDER BY name DESC

Query name which contain the letter  a.
SELECT * FROM person WHERE name LIKE '%a%'

Query only unique name:
SELECT DISTINCT(name) FROM person
This query is useful when we have many duplicate data of the same value.

Count total line in the table:
SELECT COUNT(name) FROM person

19 April 2013

Basic SQL tutorial



INTRO:
SQL is a programming languages designed for managing data. It is used for data storage or database storage. MySQL is the most popular among database management storage system. Others are Oracle, Windows Access, PostgreSQL, SQLite etc. Database are use from Office productivity to storage of various data type.

This tutorial will cover all the basic of the above and more database system..

SQL look like this..
SELECT * FROM table

Create a database:
CREATE DATABASE test
This will create a database with name  'test'.

Create a table:
CREATE TABLE person ( `name` VARCHAR(12), `age` VARCHAR(3), `gender` VARCHAR(6) )
This will create a table with name  'person' having column  name, age, gender.

Add a data to table:
INSERT INTO person (name, age, gender) VALUES ('anil', '18', 'male')
This will add a line into the table  person  to the column  name, age, gender  with value  anil, 18, male  respectively.

Check if the data/line has been added:
SELECT * FROM person
Output:
name age gender
anil 18 male


Note:
* the number in  VARCHAR(12)  signify only 12 characters will be saved and rest omitted. If we enter a name  'verylonglongname' (16 char), the saved name will only be  'verylonglong' (12 char), last 4 char omitted.


11 April 2013

BACKUP FACEBOOK PROFILE



Facebook is the leading social network, there is no doubt. It has more than 1 billion registered user. There is hardly any one who had not heard (or using) it.

This tutorial is an example on how to backup/download 'facebook profile' (our own profile). Frustated at not finding a single tutorial on how to backup my user profile. i went ahead and created this tutorial. back to the point, we will use 'cURL' (and 'wget') for this purpose as it is available for almost all system.

Facebook data are available from 'https://graph.facebook.com'. Basic info like id, username, name, link, gender & locale are available publicily. Throw in an access token you have all data that is in public or visible to friends. Example below:
https://graph.facebook.com/jor.teron

Required:
* cURL or wget
* User ID (UID)
* facebook access_token
* Basic idea on FQL and FQL tables (optional)

This method work by invoking graph explorer...
https://graph.facebook.com/fql?q=FQL_QUERY&access_token=ACCESS_TOKEN
where  FQL_QUERY  is the FQL query implemented by facebook. If  FQL_QUERY  is..
select description from group where gid=XXXXXXXX
..then url will be like.
https://graph.facebook.com/fql?q=select+description+from+group+where+gid=XXXXXXXX&access_token=ACCESS_TOKEN


STEP TO FOLLOW:
1) Goto Graph API Explorer, https://developers.facebook.com/tools/explorer. Login if necessary. Click 'Get Access Token' button. Select appropriate permission. save it. Copy the access token (those jumbled alphabet).

2) Note down your UID.

3) Open 'Command Prompt' and type in the following.
for cURL:
curl --user-agent 'Firefox 10' \
--output file.txt \
"https://graph.facebook.com/fql?q=select+uid,username,name+from+user+where+uid=UID&access_token=ACCESS_TOKEN"

for wget:
wget --user-agent='Firefox 10' \
--output-document=file.txt \
"https://graph.facebook.com/fql?q=select+uid,username,name+from+user+where+uid=UID&access_token=ACCESS_TOKEN"

note:
* Replace UID and ACCESS_TOKEN with its respective values you got in step 2 and 1 respectively.
* ACCESS_TOKEN is valid only for 1 hour, so you will need to get it (again) later if needed.

In the above example it'll download User Profile (containing id, username, name) and save it to 'file.txt'. You can specify more column if needed.


To download photos:
curl --user-agent 'Firefox 10' \
--output photo.txt \
"https://graph.facebook.com/fql?q=select+src_big+from+photo+where+owner=UID&access_token=ACCESS_TOKEN"
Sort out photos links using grep, sed, awk or regex to download them. In these way one can download facebook data from profile to photos, comments to likes, pokes to messages etc.


If FQL intimate you, there is an easier way to fetch data by using Graph Search....
https://graph.facebook.com/USER?fields=GRAPH_OBJECT&access_token=ACCESS_TOKEN
Example:
https://graph.facebook.com/jor.teron?fields=id,username,name&access_token=ACCESS_TOKEN

This tutorial will benefit those who want to backup their facebook data. Alternatively if you find this process hard to follow you can use facebook own feature 'Copy Facebook'.




12 March 2013

netstat usage example


Sometimes we need to know who are connected to our system. this can be to find malware or botnet that may be connecting us to somewhere. or some trojan stealling our data. end point is we need to find out network activities. this can be done with 'netstat'.


running netstat command will display all connection in a unix system.

netstat



to find out all TCP connection with netstat.

netstat -t



to find out all TCP and UDP connection...

netstat -tu



to find out all connection initiated by a program through TCP..

netstat -tp



to output all information in numeric format..

netstat -n



to find out all incoming connection and listening to..

netstat -l



you can also combine them..

netstat -tn



this will output TCP connection in Numeric format.

netstat -tupn


this will output all connection made by a software program in Numeric format.


these above are few example of netstat. you can check out man page for more.


put this script inside your bash profile in /home/user/.bashrc

#!/bin/bash

connection()
{
cat=$( netstat -tun | sed '1,2 d' | awk '{print $5}' | sed -r 's/(.*)\:(.*)/\1/g' | sort | uniq );

for i in $cat; do
netname=$( whois $i | grep -i netname | awk '{print $2}' );
echo "connection with: $netname ($i)";
done;
}


now open 'terminal' and type 'connection'.

this is just one stupid script. you can build better than this.
godspeed.