I love Free Software!

Pages

Funny Quotes to Think

When you say "I wrote a program that crashed Windows", people just stare at You blankly and say "Hey, I got those with the system, for free"

-Torvalds, Linus(1995-03-08)-

Sunday, September 4, 2011

Install Kernel 3.0.4

It is always good to say that you have latest kernel running in your machine. I have upgraded kernel from debian experimental and testing repositories . That was simple and straight forward. But you get real happy when you build a kernel from the source.
This was my first experience in upgrading kernel to 3.0.4 from source and even I don't know whether I can successfully complete or not. But I did this and love to share my experience with all you guys!

Before dive in to this just walk-through this document to learn about kernel.

Download the latest kernel from Linux Kernel Archive 

# wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.0.4.tar.bz2

Extract the kernel
#  bzip2 -dc linux-3.X.tar.bz2 | tar xvf -

Move to the directory where kernel source code is extracted
# mv linux-3.0.4/

Configure your kernel
Use make menuconfig or make config for configuring your kernel. I tried make menuconfig this will give you text based menus
# make menuconfig

Make the kernel 
# make bzImage 

Making kernel modules 
# make modules

This will compile all the modules for kernel 3.0.1


Install the modules compiled
# make modules_install
This will copy all kernel modules to /lib/modules/3.0.4.

Install the new kernel 
# make install
This will copy files vmlinuz-3.0.4, initrd.img-3.0.4 and config-3.0.4 to your /boot directory.
Execute below command in your shell, if initrd.img-3.0.4 is not created.
# update-initramfs -u -k 3.0.4

Configure your Grub
This document explains how to configure new kernel in grub2. grub users please excuse. Check below link to learn more about grub2

Edit /etc/grub.d/40_custom file and add below configuration for new menu item. Please make sure that you are not removing anything which already present in this file

menuentry 'Ubuntu, with Linux 3.0.4' --class ubuntu --class gnu-linux --class gnu --class os {
        recordfail
        insmod ext2
        set root='(hd0,1)'
        search --no-floppy --fs-uuid --set c933488a-c517-465e-9ecf-4744806b3a7a
        linux   /boot/vmlinuz-3.0.4 root=UUID=c933488a-c517-465e-9ecf-4744806b3a7a ro   quiet splash
        initrd  /boot/initrd.img-3.0.4
}

c933488a-c517-465e-9ecf-4744806b3a7a is the UUID. replace this ID with yours. For more information about UUID, wikipedia is the good source.
Use below command to find the UUID
# blkid

Update your grub configuration
# update-grub

Reboot with new kernel
Now reboot your machine. Once you boot with new kernel, execute uname -a in your shell to find the kernel version.

Linux pranavam 3.0.4 #1 SMP Sun Sep 4 12:28:48 IST 2011 i686 GNU/Linux

Wednesday, April 27, 2011

Quota report using LDAP and Dict

This script will export all LDAP information including current quota usage. You should use quota dict for quota storage

LDAP attributes
  1. givenName
  2. sn
  3. uid
  4. mail
  5. quota

This is the way how script will work :

#!/usr/bin/perl
# This script will export LDAP information including current quota usage.
# Install NET::LDAP, DBI, MIME::Lite for running this script.
# You have full freedom to modify this script. This will help me to improve the usage.
# Please feel free to reach me on praveen.velu84@yahoo.com

use Net::LDAP;
use DBI;
use MIME::Lite;

# Create a file for storing data
open (MYFILE, '> /tmp/quota_report.csv');
# Modify connection settings of dovecotdict database
my $dbh = DBI->connect("DBI:Pg:dbname=dovecot;host=localhost", "dovecot", "paassword", {'RaiseError' => 1});
my $sth = $dbh->prepare('SELECT * from quota where username = ?') or die "Couldn't prepare statement: " . $dbh->errstr;
$ldap = Net::LDAP->new("localhost");

# Modify your LDAP connectivity.
$ldap->bind("cn=admin,dc=example,dc=com", password=>"secret");
$mesg = $ldap->search(filter=>"(&(mail=*)(objectclass=posixAccount))", base=>"dc=example,dc=com");
print MYFILE "User_Name;First_Name;Last_Name;Email;LDAP_quota(MB);Quota_Usage(MB);No_of_messages\n";
@entries = $mesg->entries;
foreach $entry (@entries){
                $name = $entry->get_value("uid");
                $fname = $entry->get_value("givenName");
                $lname = $entry->get_value("sn");
                $mail = $entry->get_value("mail");
                $quota = $entry->get_value("quota");
$sth->execute($mail);
@data = $sth->fetchrow_array();
$usedquotamb = ($data[1]/1048576);
$quotausage = int $usedquotamb;
$messages = $data[2];
                print MYFILE $name . ";" . $fname . ";" . $lname . ";" .$mail . ";" . $quota . ";" . $quotausage . ";" . $messages ."\n"
}
close MYFILE;

# Senting mail to administrator. Replace postmaster email id with your email id
my $msg = MIME::Lite->new(
    From    => 'postmaster@example.com',
    To      => 'admin@example.com',
    Subject => 'LDAP quota report',
    Type    => 'multipart/mixed',
);
$msg->attach(
    Type     => 'TEXT',
    Data     => "Dear Sir, \n\nThis is an automated message. Please find attached User Quota Report.\n\nEmail Administrator ",
);

$msg->attach(
    Type     => 'text/csv',
    Path     => '/tmp/to_report.csv',
    Filename => 'quota_report.csv',
);

$msg->send;
$dbh->disconnect;