Wednesday, November 16, 2011

Manual Installation of Perl Modules

Most of the commonly used Perl modules can be downloaded from the CPAN website. The installation steps are straightforward.
1. Browse the CPAN website, identify the module package you need and then download it using a utility such as wget.
[root@bigboy tmp]# wget http://www.cpan.org/authors/id/M/MA/MARKOV/MailTools-1.74.tar.gz
--15:07:36--  http://www.cpan.org/authors/id/M/MA/MARKOV/MailTools-1.74.tar.gz
           => `MailTools-1.74.tar.gz'
Resolving www.cpan.org... 66.39.76.93
Connecting to www.cpan.org|66.39.76.93|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 47,783 (47K) [application/x-tar]

100%[===================================>] 47,783       100.88K/s             

15:07:38 (100.51 KB/s) - `MailTools-1.74.tar.gz' saved [47783/47783]

[root@bigboy tmp]#
2. Extract the file from the package with the tar command.
[root@bigboy tmp]# tar -xzvf MailTools-1.74.tar.gz 
MailTools-1.74/
MailTools-1.74/t/
...
...
...
MailTools-1.74/ChangeLog
MailTools-1.74/MANIFEST
[root@bigboy tmp]#
3. Enter the newly created directory with the same name as the TAR file, and install the module with the following commands.
  • perl Makefile.PL
  • make
  • make test
[root@bigboy tmp]# cd MailTools-1.74
[root@bigboy MailTools-1.74]# perl Makefile.PL
Checking for Net::SMTP...ok
Checking for Net::Domain...ok
Checking for IO::Handle...ok
Checking if your kit is complete...
Looks good
Writing Makefile for Mail
[root@bigboy MailTools-1.74]# make
cp Mail/Cap.pm blib/lib/Mail/Cap.pm
cp Mail/Mailer/rfc822.pm blib/lib/Mail/Mailer/rfc822.pm
...
...
...
Manifying blib/man3/Mail::Util.3pm
Manifying blib/man3/Mail::Address.3pm
[root@bigboy MailTools-1.74]# make test
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/extract.....ok                                                             
...
...
...
All tests successful.
Files=7, Tests=95,  2 wallclock secs ( 1.28 cusr +  0.29 csys =  1.57 CPU)
[root@bigboy MailTools-1.74]# 
Your Perl module installation should now be complete.
Note: The output of the perl Makefile.PL command will tell you whether there are any other required modules. You can either install them all manually, running the risk of having to install more prerequisite modules for these prerequisite modules, or you can use automated updates which will be covered next.

Sunday, October 23, 2011

FTP Server setup on Ubuntu.

          VSFTPD is a FTP deamon available in Ubuntu and it is easy to install, setup and maintain.

Steps :

1. Install vsftpd from Ubuntu repositories by typing the following command in a terminal Window.
sudo apt-get install vsftpd

2. During installation, user ftp will get generated with default ftp directory as "/home/ftp". If you like to change the same to another directory, then type,

"sudo usermod -d /srv/ftp ftp" 

where /srv/ftp is the new ftp directory and ftp stands for username.

3.You can restart the ftp server by typing the following command,

"/etc/init.d/vsftpd restart".

Configuration :

The default configuration file for vsftpd is /etc/vsftpd.conf. We can configure the vsftod ftp server by editing this file, as per our requirement.

1. To enable local users to login and upload files, edit the vsftpd.conf file as,
local_enable=YES
write_enable=YES
 2. To enable anonymous user to upload files, use
anon_upload_enable=YES 
3. To restrict users only to their home directory, use
chroot_local_user=YES
To include a list of users to be able to access their home directories, use
chroot_list_file=/etc/vsftpd.chroot_list
where vsftpd.chroot_list is a file includes list of users (one per line).

4. Restart vsftpd, /etc/init.d/vsftpd restart

Access :

Using a browser type "ftp://ip_address_of_server/". This will prompt for username and Password. On successful login, you can view files that are related to your user account.

Note : 
1. You can also view files remotely, under file-browser, like nautilus, etc.
2. The FTP server is not encrypted and is unsafe to use unless made secured by using  SSL (secure socket layer).



Friday, October 7, 2011

Installation of Spreadsheet::WriteExcel module for Perl

    Spreadsheet::WriteExcel module can be used to write/edit excel files. The installation procedure for this module is as given below.

1. Download http://perlmirror.indialinks.com/authors/id/J/JM/JMCNAMARA/Spreadsheet-WriteExcel-2.37.tar.gz.

2. Unzip the module as follows, tar -zxvf Spreadsheet-WriteExcel-2.xx.tar.gz.
3. The module can be installed using the standard Perl procedure:
          perl Makefile.PL
        make
        make test
        make install
    # You may need to be root
         make clean      # or make realclean

That's all !!!!!. Now you can write Perl programs to edit an Excel.

Sample program :

    #!/usr/bin/perl -w
    
    use strict;
    use Spreadsheet::WriteExcel;
    
    # Create a new Excel workbook
    my $workbook = Spreadsheet::WriteExcel->new("regions.xls");
    
    # Add some worksheets
    my $north = $workbook->addworksheet("North");
    my $south = $workbook->addworksheet("South");
    my $east  = $workbook->addworksheet("East");
    my $west  = $workbook->addworksheet("West");
    
    # Add a caption to each worksheet
    foreach my $worksheet (@{$workbook->{worksheets}}) {
       $worksheet->write(0, 0, "Sales");
    }

        # Write some data
    $north->write(0, 1, 200000);
    $south->write(0, 1, 100000);
    $east->write (0, 1, 150000);
    $west->write (0, 1, 100000);
    
    # Set the active worksheet
    $south->activate();

Tuesday, October 4, 2011

Parse EXCEL tools under Perl.

This is a sample Perl Program to parse/read excel.

#!/usr/bin/perl -w

use strict;
use Spreadsheet::ParseExcel;

my $oExcel = new Spreadsheet::ParseExcel;

die "You must provide a filename to $0 to be parsed as an Excel file" unless @ARGV;

my $oBook = $oExcel->Parse($ARGV[0]);
my($iR, $iC, $oWkS, $oWkC);
print "FILE  :", $oBook->{File} , "\n";
print "COUNT :", $oBook->{SheetCount} , "\n";

print "AUTHOR:", $oBook->{Author} , "\n"
 if defined $oBook->{Author};

for(my $iSheet=0; $iSheet < $oBook->{SheetCount} ; $iSheet++)
{
 $oWkS = $oBook->{Worksheet}[$iSheet];
 print "--------- SHEET:", $oWkS->{Name}, "\n";
 for(my $iR = $oWkS->{MinRow} ;
     defined $oWkS->{MaxRow} && $iR <= $oWkS->{MaxRow} ;
     $iR++)
 {
  for(my $iC = $oWkS->{MinCol} ;
      defined $oWkS->{MaxCol} && $iC <= $oWkS->{MaxCol} ;
      $iC++)
  {
   $oWkC = $oWkS->{Cells}[$iR][$iC];
   print "( $iR , $iC ) =>", $oWkC->Value, "\n" if($oWkC);
  }
 }
}

Usage : Type "Path_to_perlfile Excel_filename_that_need_to_be_parsed.xls", in terminal window to read and display contents of an excel file.


Before that you need to ensure that the supporting modules are installed already. Under Ubuntu, the modules can be installed using command "sudo apt-get install libspreadsheet-parseexcel-perl" OR you can download the sources and copy the same to standard location of perl.

Saturday, February 19, 2011

Execute system commands using PHP under Root Priviledges.


Suppose you have set-up a webserver (apache2) with PHP enabled and you need to execute some system commands or your own scripts under super user / root priviledges, then the following method may help you to solve the problem, especially under Ubuntu.

Step 1:  Run sudo visudo in a Terminal window.

Step 2:  Add the below lines at the end of the file, depending on your requirement.
 
www-data ALL=NOPASSWD: /sbin/iptables, /usr/bin/du
OR
www-data ALL=NOPASSWD: ALL

Step 3:  Try an exec command under PHP script to test the settings.

e.g : exec ("sudo iptables -P FORWARD ACCEPT");


Friday, November 26, 2010

Fast Mail Merge - Openoffice.org extension.

There is a new extension tool to Openoffice.org called Fast Mail Merge. This will help you to send multiple email messages within a short period of time. In addition to that it provides enhanced features for existing Mail Merge Options.

If you need to download the extension file from the link given below,

http://extensions.services.openoffice.org/e-files/1082/7/FastMailMerge-0.8.1.oxt

To INSTALL, Select Tools-->Extension Manager under Openoffice.org software and add....

To work on the tool, open a Openoffice.Org spreadsheet database and Select the FMM button just under File Menu. This will open a small widow wizard which will ask for some inputs. Proceed with your options.

Saturday, November 13, 2010

Boot Multiple Operating Systems (OSs) using a USB Drive.

There are some cases where you may need to maintain many number of CDs, DVDs and USB drives written with different Operating Systems for the purpose of installation or booting Live OS. Its really tiresome to create different OS images on different devices. Hence, here is a solution that helps you to maintain a Single device with Large number of OS images installed in it. The method is very easy and you may delete or add any number of OS images (depending on the size of your device) without much efforts.

In this method, we make use of USB (pen) drives. I prefer Ubuntu Linux to do this and the steps are as explained below.

Steps:

1. Get a USB drive with 4GB / 8 GB or higher memory capacity. Format the drive to vfat or ext4 filesystem.


Note : 
        a). In ubuntu you may use gparted command to do this. Or you my use fdisk too.
        b). You need to unmount the drive before partitioning.

2. Now, install grub (which is known as a bootloader) on the drive with following command.

sudo grub-install --no-floppy --root-directory=/mnt /dev/sdc 

Note : 
        a). Where /mnt is the mount location for the drive. /dev/sdc is device ID.
        b). Please ensure that you have grub2 installed in your  Ubuntu, in order to get better results.


After "grub-install", you will be able to see a folder boot which contains subfolder grub with lots of files in it.

3.  Add menus to your "grub" by editing the file grub.cfg.

For example :


menuentry "Ubuntu 10.04 Desktop i386" {
  loopback loop /iso/ubuntu-10.04-desktop-i386.iso
  linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/iso/ubuntu-10.04-
desktop-i386.iso noeject noprompt --
  initrd (loop)/casper/initrd.lz
}
 
Add menus If your grub.cfg contents are as given above, then this will show 
a Menu "Ubuntu 10.04 Desktop i386" while you boot from the USB Drive.
You may add sufficient number of menus depending on the number of .iso files.
4. Now create a folder named "iso" in the same location where your boot folder is.
5. Copy iso image, Ubuntu-10.04-desktop-i386.iso into the "iso" folder.
You may copy more ".iso" images of different OSs and add the menu entry into the 
"grub.cfg" file.
6. Restart your computer and select the USB drive as the boot device. This will 
display a menu list of OSs to select and boot.
Thats all folks!!!!!
grub