A simple pythonic script to log internet bandwidth usage on Linux

We often want to log internet bandwidth on our laptops or PCs in order to track our usage over a period of time. This also comes handy to cross-check our usage with that of our ISP’s invoice. Now how to do it on linux? While the Windows folk have all kinds of utilities for this kind of thing, we lunix folk have to invent it ourselves.

Some time ago, I wrote this small python script that writes your bandwidth stats to a log file each time you disconnect your internet connection. This, I’ve tested on ubuntu 12.04 and debian wheezy:

Source file: Tata.py

#!/usr/bin/python
# author: Prahlad Yeri
import subprocess, os, datetime, sys
def execute(command):
    try:
        p=subprocess.Popen(command, shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
        p.wait()
        result=p.communicate()
        #print str(result)
        if len(result[0])>0:
            return result[0].strip()
        else:
            return result[1].strip()
    except Exception as e:
        print ‘error occured:’ + errorstring
        return errorstring
#main
mypath = ‘/etc/NetworkManager/dispatcher.d/’
iface = sys.argv[1].strip()
status = sys.argv[2].strip()
log=open(mypath + ‘tata.log’,’a’)
#log.write(iface + ‘:’ + status + ‘\n’)
#log.close()
for part in sys.argv:
        log.write(‘argv:’ + part + ‘\n’)
if (iface == ‘ppp0’ or iface == ‘ttyUSB0’) and status == ‘down’:
        s = execute(‘iptables -L -v’)
        rules = s.splitlines()
        rx,tx = 0,0
        rxdrop, txdrop = 0,0
        inrule = False
        outrule = False
        for rule in rules:
                log.write(‘rule:’ + rule.strip() + ‘\n’)
                words = rule.strip().split()
                if rule.strip().startswith(“Chain OUTPUT”):
                        log.write(‘switch to outrule’)
                        outrule = True
                        inrule = False
                elif rule.strip().startswith(“Chain INPUT”):
                        log.write(‘switch to inrule’)
                        inrule = True
                        outrule = False
                elif rule.strip().startswith(“Chain FORWARD”):
                        log.write(‘switch to no rule’)
                        inrule=False
                        outrule=False
                elif len(words) >=3:
                        if words[6].strip() == “ppp0”:
                                #log.write(‘bytes=’ + words[1]
                                if inrule:
                                        if words[2].strip() == ‘DROP’:
                                                rxdrop += int(words[1].replace(‘K’,’000′).replace(‘M’,’000000′))
                                        else:
                                                rx += int(words[1].replace(‘K’,’000′).replace(‘M’,’000000′))
                                elif outrule:
                                        if words[2].strip() == ‘DROP’:
                                                txdrop += int(words[1].replace(‘K’,’000′).replace(‘M’,’000000′))
                                        else:
                                                tx += int(words[1].replace(‘K’,’000′).replace(‘M’,’000000′))
        #print ‘rx=’ + str(rx) + ‘ tx=’ + str(tx)
        #print ‘rxdrop=’ + str(rxdrop) + ‘ txdrop=’ + str(txdrop)
        execute(“iptables –zero”)
        header=”
        lines=[]
        if not os.path.exists(mypath + ‘usage.csv’):
                #create header
                header = ‘date,rx,tx,rx-dropped,tx-dropped,rx-tot,tx-tot\n’
        f = open(mypath + ‘usage.csv’,’a’)
        if len(header) > 0:
                lines.append(header)
        lines.append(str(datetime.datetime.now()).split(‘.’)[0] + ‘,’ + str(rx) + ‘,’ + str(tx) + ‘,’ + str(rxdrop) + ‘,’ + str(txdrop) + ‘,’ + str(rx+rxdrop) + ‘,’ + str(tx+txdrop) + ‘\n’)
        #rx = execute(‘cat /sys/class/net/ppp0/statistics/rx_bytes’)
        #tx = execute(‘cat /sys/class/net/ppp0/statistics/tx_bytes’)
        #strdate=str(datetime.datetime.now())
        #line = strdate + ‘,’ + rx + ‘,’ + tx + ‘\n’
        f.writelines(lines)
        f.close()
        log.close()
        sys.exit(0)

In the above script, replace ppp0 with the interface-name for the name of interface through which you access internet. For mobile broadbands it is typically ppp0, but you can issue the “ifconfig” command to list them all and make sure.

You have to place this script at /etc/NetworkManager/dispatcher.d on debian/ubuntu systems so that it runs each time you stop using the modem. In case of other systems, or in case you don’t use NetworkManager, refer to your distro documentation to check the folder/script which is executed when an interface is down.

A Python finds out which is the best performing Linux distro!

python

With more and more linux distributions competing among themselves for the userspace, we are currently living in the best of times as far as choice in open-source software is concerned. However, more the number of choices, more is the head-scratching to decide what to choose amongst them. Like many, I am also one of the victims of “distro-hopping”. No sooner a major distribution declares a new version, I’m itching to try one out in my virtual box or as a LiveCD version. Few days ago, this benchmarking idea occurred to me.

I’m a software developer and my requirements were clear. I wanted a distro that is good at performance. Since my desktop is cluttered with “heavy-duty” programs like Eclipse-ADT, Java, IDLE, etc., performance was my primary concern. I mostly write application software and android apps, so things like disk I/O, memory and CPU utilization matter.

With these things in my mind, I was seeking a simple way to do a quick benchmark of various distros to find out what suits my needs. Thats when this idea came to me – Almost all distros come preloaded with a general-purpose scripting language called python which could be summoned for the job. I took “time taken in milliseconds” to do 5 basic tasks to decide on the performance. These tasks were:

  1. Zip-test: A test to compress a large file to a zip file, and extract in back in python code.
  2. Random-test: Generate 5 million random numbers and round them to zero decimals.
  3. I/O test: Write a unicode string ‘spam and eggs’ 5 million times to a text file, and read them back.
  4. CSV test: Generate a CSV spreadsheet with 5 million rows in it, and read them back.
  5. Bandwidth test: Download the 800K akonadi RPM file from IIT Kanpur’s website.

(The last one was just for the sake of completeness. Internet bandwidth depends more on other parameters such as your ISP limits, time of the day, latency, etc. rather than the disto you are using).

The contestants in the arena were:

  1. openSUSE 12.2
  2. Debian 7 (GNOME version)
  3. Fedora 18
  4. Ubuntu 12.04 LTS
  5. Xubuntu 12.04

My previous experience with Ubuntu made be biased towards it, but the tests showed me how wrong I was. Also, from what I’d read in most blogs on the Internet, KDE was one of the most bloated distros ever. However, in my tests KDE on openSUSE topped the race in most parameters, though the credit should go to openSUSE for optimizing the KDE. The second spot saw Fedora and Debian fighting amongst them, while Ubuntu (that I was presently using) fared the worst! Here are the detailed results:

Test zt1

(compress)

zt2

(archive)

random io csv bandwidth
debian1 7622 2753 9142 5732 12784 118978
debian2 7724 2752 9161 5287 12112 92386
fedora18_1 8605 4168 6287 5972 12750 0
fedora18_2 7762 4164 6419 6160 12818 0
openSUSE1 9001 2313 5915 5904 12715 115999
openSUSE2 7253 2245 6035 5935 11492 71257
precise1 9649 5012 8807 6846 13552 78560
precise2 10555 4434 8890 7229 13455 48286
xubuntu1 13305 4827 8954 5839 14676 58538
xubuntu2 10826 4760 8934 7908 12802 52768

*Above figures represent time-taken in milliseconds

The bandwidth test could not be performed on fedora as the Live CD did not have the wget package installed, but I did not need that to get a general idea of things.

My Conclusion: openSUSE wins the race, though Debian-7 and Fedora-18 are also fine distros for performance.

Here is the entire python benchmarking script that you may customize as per your requirement (change initializing variables in the script and run by issuing “python benchmark.py” from the shell):

 

import sys,time,os
import zipfile,random,csv
import subprocess
from zipfile import ZipFile,ZIP_DEFLATED
from random import random

##Variables
#This should be initially present before running the program:
test_name=’debian1′
file_to_extract = “VirtualBox.exe” #”dotnetfx35.exe”
##

def timer(test):
t1=time.time()#.clock()
elapsed=0
#
if test == “ziptest1”:
ziptest1()
elif test == “ziptest2”:
ziptest2()
elif test == “randomtest”:
randomtest()
elif test==”iotest”:
iotest()
elif test==”csvtest”:
csvtest()
elif test==”bwtest”:
bwtest()

elapsed=time.time()-t1
timetaken=round(elapsed*1000,0)
print test,timetaken,”msecs.”
return timetaken

def ziptest1():
myzip=zipfile.ZipFile(‘t.zip’,’w’,ZIP_DEFLATED) #ZIP_STORED
myzip.write(file_to_extract)
myzip.close()
return

def ziptest2():
os.remove(file_to_extract)
myzip=zipfile.ZipFile(‘t.zip’,’r’)
myzip.extractall()
myzip.close()
return

def randomtest():
for i in range(1,5000000):
r = round(random()*100,0);
#print r
return

def iotest():
file=open(‘myfile1k.txt’,’w’)
for i in range(1,5000000):
file.write(u’spam and eggs’)
file.close()
#
file=open(‘myfile1k.txt’,’r’)
s=file.readline()
while (s!=”):
#print s
s=file.readline()
file.close()
return

def csvtest():
file=open(‘myfile.csv’,’w+b’)
#
writer= csv.writer(file,delimiter=’,’,quotechar=’|’)#,quoting=csv.QUOTE_MINIMAL)
for i in range(1,5000000):
writer.writerow([‘spam’,’eggs’,’spam1′])
#writer.close()
file=open(‘myfile.csv’,’r+b’)
reader=csv.reader(file,delimiter=’,’,quotechar=’|’)
for row in reader:
s= ‘,’.join(row)
#reader.close()
#
file.close()
return

def bwtest():
subprocess.call([“wget”,”http://mirror.cse.iitk.ac.in/fedora/releases/18/Fedora/i386/os/Packages/a/akonadi-1.8.1-1.fc18.i686.rpm”,”-O akonadi.rpm”])
#subprocess.call([“wget”,”http://www.google.com”,”-O”,”akonadi.rpm”])
return

if __name__ == “__main__”:
#print time.strftime(“%d-%m-%y %H:%M”, time.gmtime())
#print time.strftime(“%d-%m-%y %H:%M”, time.localtime())
zt1=timer(“ziptest1”)
zt2=timer(“ziptest2”)
random=timer(“randomtest”)
io=timer(“iotest”)
cst=timer(“csvtest”)
bw=timer(“bwtest”)

#Store results to csv file.
file=open(‘results.csv’,’ab’)
writer= csv.writer(file,delimiter=’,’,quotechar=’|’)
#writer.writerow([‘test’,’zt1′,’zt2′,’random’,’io’,’cst’,’bw’])
writer.writerow([test_name,zt1,zt2,random,io,cst,bw])
file.close()
print ‘\n\nWritten results.csv’
#
exit(0)

How to turn your Linux machine into a wifi Access Point

Wifi Access Point

Update on 08-jul-2014: To easily create a wifi AP on ubuntu and other distros, use the hotspotd daemon – Opensource, available on github.

To install:

wget https://github.com/prahladyeri/hotspotd/raw/master/dist/hotspotd-0.1.4.tar.gz
tar xvf hotspotd-0.1.tar.gz
cd hotspotd-0.1/
sudo python setup.py install

Few weeks ago I stumbled upon the challenge of creating a wifi access-point on my ubuntu 12.04 linux machine. Whilst I knew about ubuntu’s built-in wifi hotspot feature that works in adhoc mode, it was pretty much useless to connect to my new Android smartphone since it did not support the ad-hoc wifi mode. Most phones these days only support the infrastructure mode (a.k.a access-point mode), and in fact, they won’t even detect devices running on ad-hoc mode. After doing some research, I gathered this simple (though a bit lengthy) set of steps to turn your linux machine into a wifi access-point:

Pre-requsites:

1. Ability of your wireless card to support infrastructure mode. To find out:

(i) Find your kernel driver module in use by issuing the below command:
lspci -k | grep -A 3 -i “network”
(In my case, the driver in use was ath9k)
(ii) Now, use the below command to find out your wifi capabilities (replace ath9k by your kernel driver):
modinfo ath9k | grep ‘depend’
(iii) If the above output includes “mac80211” then it means your wifi card will support the AP mode.

2. Hostapd software: Hostapd is the standard linux daemon that will be used to create your access-point.

3. Dhcp software: Even after hostapd creates the AP and your device detects it, you will still need a  dhcp server to assign a dynamic ip-address to your AP client. (unless you are assigning static address to each device)

4. Iptables: In order to share internet on your AP clients through wifi (a.k.a reverse-tethering), you will have to setup a NAT (Network Address Translation), so that your linux machine, acting as a middleman transfers the internet packets to and from your AP client and the internet modem card (typically ppp0).

EDIT: As of 06-Jul-2013, I’ve developed a python program with GTK+ front end called ‘pyforward’ which automates the below procedure for you. You can find it here: https://sourceforge.net/projects/pyforward/

Procedure:

1. Install the hostapd package. On ubuntu:
sudo apt-get install hostapd

2. Install Dhcp server. On ubuntu:
sudo apt-get install dhcp3-server

3. Make sure that packet forwarding is turned on. This means that your computer is able to forward request of connected clients to other devices, which in my case happened to be from wlan0 to ppp0. (forwarding is different than sending and receiving packets). To enable packet forwarding, issue the following linux command:

sysctl -w net.ipv4.ip_forward=1

To make the change permanent, make sure that the below line is uncommented in your /etc/sysctl.conf file. If not, change it and restart your machine:

        net.ipv4.ip_forward=1

4. The next step is to set up your dhcp. First, decide the subnet and ip-address range in which your virtual AP will sit and your clients will be automatically assigned using dhcp. In my case, I used the subnet 192.168.5.0. My virtual AP is assigned 192.168.5.1 and each connecting wifi device gets an IP in range of 192.168.5.3-45. In order to set the rule, add this block to your /etc/dhcp/dhcpd.conf:

subnet
192.168.5.0 netmask 255.255.255.0 {
interface “wlan0”;
# — default gateway
option routers
192.168.5.1;
# — Netmask
option subnet-mask
255.255.255.0;
# — Broadcast Address
option broadcast-address
192.168.5.255;
# — Domain name servers, tells the clients which DNS servers to use.
#option domain-name-servers
#10.0.0.1, 8.8.8.8, 8.8.4.4;
option time-offset
0;
#range 10.0.0.3 10.0.0.13;
range 192.168.5.3 192.168.5.45;
default-lease-time 1209600;
max-lease-time 1814400;
}

5. Now that packet forwarding and dhcp are set up, we have to create a NAT (Network Address Translation) table using iptables. Please note that if you are using any other controlling software on top of iptables such as ufw firewall or firestarter, then you have to manage the NAT yourself. In that case, there is no need to follow this step:

Create a file called iptables_start in your home folder using gedit or nano and add the below contents to it:

#!/bin/bash
            #First, delete all existing rules
iptables –flush
iptables –delete-chain
iptables –table nat –delete-chain
iptables –table nat -F
iptables –table nat -X

#Allow incoming – already established connections:
iptables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT

#Allow outgoing on tcp80, tcp443, udp53
iptables -A OUTPUT -p tcp –dport 80 -j ACCEPT
iptables -A OUTPUT -p tcp –dport 443 -j ACCEPT
iptables -A OUTPUT -p udp –dport 53 -j ACCEPT

#NAT Forwarding for wifi access point
iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
iptables -A FORWARD -i ppp0 -o wlan0 -j ACCEPT -m state –state RELATED,ESTABLISHED
iptables -A FORWARD -i wlan0 -o ppp0 -j ACCEPT

#Block all incoming & outgoing traffic after that
iptables -A INPUT -j DROP
iptables -A OUTPUT -j DROP

Please note that some of the above rules are customized according to my particular requirement. For eg: I’m allowing outgoing traffic on only tcp80, tcp443 & udp53 ports. Your requirements may be different. Only the NAT forwarding part is what you should be concerned about. Also note that here ppp0 refers to the interface that connects to the internet using modem, and wlan0 is your wifi AP interface that connects to client devices that need internet access.

Your particular interfaces might have different names. You may query all interfaces by using ifconfig command to be sure of them.

Once you create the above file, make it executable using a command like:

sudo chmod +x /home/user_xyz/iptables_start

Now run it by issuing “sudo ./iptables_start” in your home folder. Each time you have to make any changes to your firewall, you may edit and run this file. To test your new iptables rules, issue the command “sudo iptables –list”. It will list your newly added rules.

Once you run this however, the iptables rules are set, but they are not stored permanently. To start these rules each time your computer starts, do the following:

1. Save existing rules to a file using “sudo iptables-save > /home/user_xyz/iptables.rules”.
2. Copy the iptables.rules file to your /etc folder.
3. Now, in order for your computer to load rules from iptables.rules when your network interfaces turn up, create a file called /etc/network/if-pre-up.d/iptablesload and add below script to it:
#!/bin/sh
iptables-restore < /etc/iptables.rules
exit 0

4. Make the above file executable by running “sudo chmod +x /etc/network/if-pre-up.d/iptablesload”

Test these settings by restarting your computer and issuing “sudo iptables –list”. This will list your current firewall rules.

6. Now that all hard work is done, you are ready to start your virtual AP. First, create a configuration file for the hostapd called hostapd.conf. It can be located in either /etc or your home folder:

#sets the wifi interface to use, is wlan0 in most cases
interface=wlan0
#driver to use, nl80211 works in most cases
driver=nl80211
#sets the ssid of the virtual wifi access point
ssid=YourAPName
#sets the mode of wifi, depends upon the devices you will be using. It can be a,b,g,n. Setting to g ensures backward compatiblity.
hw_mode=g
#sets the channel for your wifi
channel=6
#macaddr_acl sets options for mac address filtering. 0 means “accept unless in deny list”
macaddr_acl=0
#setting ignore_broadcast_ssid to 1 will disable the broadcasting of ssid
ignore_broadcast_ssid=0
#Sets authentication algorithm
#1 – only open system authentication
#2 – both open system authentication and shared key authentication
auth_algs=1
#####Sets WPA and WPA2 authentication#####
#wpa option sets which wpa implementation to use
#1 – wpa only
#2 – wpa2 only
#3 – both
wpa=3
#sets wpa passphrase required by the clients to authenticate themselves on the network
wpa_passphrase=your_passphrase
#sets wpa key management
wpa_key_mgmt=WPA-PSK
#sets encryption used by WPA
wpa_pairwise=TKIP
#sets encryption used by WPA2
rsn_pairwise=CCMP
#################################
#####Sets WEP authentication#####
#WEP is not recommended as it can be easily broken into
#wep_default_key=0
#wep_key0=qwert    #5,13, or 16 characters
#optionally you may also define wep_key2, wep_key3, and wep_key4
#################################
#For No encryption, you don’t need to set any options

In above script, replace YourAPName with ssid of your AP. This will be detected when you run a scan on your device. Similarly, replace your_passphrase with the actual password you wish to set up.

7. The last and final step is to create an AP script and run it. Create a file called AccessPoint in your home folder:

#!/bin/bash
ifconfig wlan0 up 192.168.5.1 netmask 255.255.255.0
sleep 5
###########Start DHCP, comment out / add relevant section##########
#Doesn’t try to run dhcpd when already running
if [ “$(ps -e | grep dhcpd)” == “” ]; then
dhcpd wlan0 &
fi
###########
#start hostapd
sleep 2
hostapd ~/hostapd.conf 1>/dev/null
killall dhcpd

8. Make above file by issuing “sudo chmod +x ~/AccessPoint”. Now execute this script in the terminal by “./AccessPoint” and keep it running. If all goes well, your devices should now be able to scan and connect to your new virtual AP.

References:

If for some reasons, all doesn’t go well, then here are some links that can help you:

Hostapd:
http://nims11.wordpress.com/2012/04/27/hostapd-the-linux-way-to-create-virtual-wifi-access-point/
http://ubuntuforums.org/showthread.php?t=151781
Iptables basics:
https://help.ubuntu.com/community/IptablesHowTo

NAT and port forwarding:
http://ubuntulinux.co.in/blog/ubuntu/nat-configuration-with-iptables-in-ubuntu/
http://www.howtoforge.com/nat-gateway-iptables-port-forwarding-dns-and-dhcp-setup-ubuntu-8.10-server

(If you have some specific issue, you can always get back to me).

Fedora vs Ubuntu vs Linux Mint for Performance

Fedora vs Ubuntu vs Linux Mint

The never ending search for that “holy grail” distribution keeps most people downloading and hopping from one distro to another without ever bothering to ask themselves why they want to use an operating system in the first place. I don’t blame them, as nowadays, the ever active “assembly-lines” of various distro factories like ubuntu, fedora and linux-mint are enough to boggle the minds of most newbies by throwing an enormous number of configuration options.

Until some time ago, I myself was one of those “holy grail” seekers endlessly installing one distro after another in the second partition of my hard drive which is always reserved for Linux. Since my full time job involves .NET programming for my organization, I have to keep the first one reserved for Win7 of course.

Anyways, coming back to my Linux endeavors, I decided to pause and look inwards. I asked myself why do I want to use Linux? Thats because I want to: 1) Learn and understand the Linux operating system and programs using a top-down approach, and 2) Learn programming on Linux – this involves a lot of things including C++, GTK+, Qt, Android and the suchlike, and 3) Doing miscellaneous things such as listening to music, some light gaming, etc.

The most obvious thing that occurred to me was one word – performance. I don’t need high-end graphics. I’m never getting into serious gaming stuff such as OpenGL. All I need is a distro that can handle as many applications and programs as I can throw at it. Since I don’t have time for doing things from scratch like LFS or ArchLinux, I shortlisted the below three candidates:

1. Ubuntu 12.04 LTS – Precise Pangolin

2. Linux Mint 14.1 – Nadia

3. Fedora 18 – Spherical Cow

Rather than search for existing benchmarks, I decided to put these gladiators in my own arena. I prepared my 16GB pendrive for a multi-boot with the above three Live versions and started testing them one by one. The stuff I threw at them was things I would normally do, such as extracting a huge (4GB) archive, format a USB pendrive, surf the net, etc. Here is how each one of them fared in the fight:

Distro Benchmarking

The verdict: Unlike the gladiators of Rome where one used to absolutely dominate over the other, the case of these linux distros is entirely different. One distro fared well in one area, while the other fared in another. For instance, Fedora was good at CPU usage, while Linux-mint did well in the RAM area. However, for my purposes, I regard Linux-mint as an ideal choice overall.

How to add or remove launchers from your gnome classic/fallback desktop panel

This is a nice little hack that comes handy when you want to add or remove launchers (shortcuts to your favorite programs such as firefox or gedit) to an existing panel, or add an entirely new panel to your gnome-classic or fallback desktop. On my Linux Mint workstation, I prefer the gnome-classic version instead of the default cinnammon desktop for reasons of speed and simplicity. I soon found out, however, that process of adding/removing launchers or adding a new panel requires a special key combination that is not easily found without going through some extensive documentation!! Here is how you do it:

To add a new launcher:

1. Press the WIN (Super) and ALT keys together.
2. While keeping them pressed, right-click the panel.
3. You will then get a popup menu saying “New Panel”, or “Add to Panel”.
4. Click on the second option and select your program.

To edit/remove an existing launcher:

1. Follow steps 1 & 2 from above.
2. You will get a popup menu saying “Move” and “Remove from Panel”.
3. Click on your choice.

How to make brightness changes permanent in your Linux Desktop?

Quite recently, I’ve faced this nagging little issue on all the distros I tried. These included Ubuntu 12.04 LTS, Linux Mint 11.1 and Fedora 18. Whenever I changed my computer’s brightness setting either through the gnome-settings applet or by using hotkeys, the changes were only temporary. On next reboot, they would vanish!! Now what is the easiest way to make your chosen setting permanent? After much googling and head-scratching, I finally arrived at the answer.

First of all, NEVER place anything like this in a startup script:

echo 4 > /sys/class/backlight/acpi_video0/brightness

(See this update if you found this folder empty or missing)

Although this command might change your brightness, again the effects are only temporary and will be lost on your next reboot. If you attempt to place this in /etc/rc.local, it may not always work due to permission issues. Instead of ending up chmod-ing the permissions to the brightness file and cause any other issues in turn, the recommended approach is to use xbacklight, the tool fit for this purpose.

Here is the easy way:

1. Install xbacklight from your package repository. On Linux Mint, I did this:

sudo apt-get install xbacklight

2. Place xbacklight command with your chosen settings in your “startup-applications” applet. In my case I had the command: xbacklight -set 50

On Mint Linux, it looked something like this:

Image for xbacklight-startup
Configure xbacklight in startup-applications applet

Thats all. This effectively sets brightness to 50% by default upon your each login. Enjoy!!

UPDATE on 04-mar-2013: I came to know today that the 3.4 kernel has broken some things related to acpi-support for setting brightness. As a result of that the /sys/class/backlight folder is empty and the xbacklight program also won't work!! Solution? Either upgrade/downgrade your kernel or add "acpi_backlight=vendor" to your menu.lst. See this link for more information:

http://superuser.com/questions/548459/how-to-change-screen-brightness-on-toshiba-satellite-l850-djs-in-linux/556745#comment683067_556745

List of development tools for Linux platform – IDEs, Compilers, etc.

One of my most recent endeavours was to set up my old linux machine for development. I chose the Debian Squeeze(6.1.5) distro because of its reputation for stability and also its minimalistic approach towards installing packages, and both these features were quite welcome. Having said that, the tools listed here can be downloaded and installed on any distro, in case they are not already included in the installation CD/DVD. Based on my development experience with these tools, this list is frequently updated with new information:

1. GCC (GNU Compiler Collection): The GCC toolchain is considered a sin-qua-non of any linux developer’s toolbox. In fact, the linux kernel itself relies on several libraries provided as part of GCC. The debian squeeze 6.1.5 includes GCC 4.4 which is pretty stable. I’ve compiled several programs in C/C++ without any issues. You can choose to install specific packages such as gcc4.4 for C, or g++4.4 for the C++ language.

Only issue is that you should not install the OpenJDK package (gcj) of the GNU collection. The reason being that it will clash with the Sun/Oracle Java version which is very much preferred if you are into Android development or use other Java features such as Swing or AWT.

GCC is one of your core tools. Whether you use Eclipse or Netbeans to code your C/C++ programs, whether you use the QTcreator or Glade for designing interfaces, GCC is one good toolchain that most IDEs rely on to build your application.

2. Java/Netbeans: You can download all the java editions for linux including Java ME/EE, documentation & samples and also the Netbeans package from here. I specifically chose the combined Netbeans+JDK7.5 to avoid getting Netbeans separately.

3. MonoDevelop: One of the most important tools that allows me to leverage my Microsoft VB.NET/C# skills on linux is the MonoDevelop IDE. Except for Microsoft proprietary classes such as System.Windows.Forms, all your .NET code is 100% portable to linux through the Mono platform. The only support that MonoDevelop lacks as of now is the ability to design ASP.NET web pages. I believe this limitation is going to be overcome pretty soon.

4. Eclipse: Eclipse was essential for me as I wanted to develop Android apps too which is easier using the Eclipse IDE. The debian squeeze CD comes with version 3.5.2 of eclipse package, whereas I wanted to try the latest Juno version, so I got it from the eclipse site. However, the eclipse SDK for linux is a tar package and not an installer package. This means you have to extract this tar separately in a folder and use eclipse from there. If you do so, ensure that the ..JDK/bin is set in your $PATH variable, so that you can invoke java from the command line. If not, then add it by editing the .profile file in your home directory (/home/xyz, etc..).

5. Android Suite: The android developer site contains complete information about how to download and install the android sdk, along with the system images for the particular android platforms for which you wish to develop. Just keep in mind that android needs the Sun/Oracle java sdk and not the OpenJDK provided by GNU to write android programs.

6. Glade: Glade is an excellent RAD tool to rapidly develop professional-looking user interfaces for your applications. Glade is based on the Gtk+ toolkit that forms the core of the GNOME desktop. Glade basically generates an xml file (similar to the XAML generated in visual-studio) that can be used in many languages such as  C, C++ and Java. However, since the Gtk+ framework is built in C, it is advisable to build your GNOME applications in C for performance benefits. Glade can also be integrated with Anjuta, a full fledged IDE to develop GNOME applications that includes full toolchain integration and debugging support.

7. QTcreator: Based on the extensive QT framework, QTcreator is to KDE desktop what Glade is to GNOME. However, don’t feel crippled because of this as everything is “mix-and-match-able” in the linux world. QT apps can run on GNOME, as do Gtk+ apps run on KDE desktop. Since QT framework is written in C++, the language is well suited to write QT apps. Qtcreator can also be integrated with KDevelop, the equivalent of Anjuta IDE on KDE.