Monday, August 6, 2012

Calculating md5sum of a given file

use Digest::MD5; # make sure to have this package added in your perl script

# Function Name : md5sum
# Input            : File for which md5sum is requested
# Output        : md5sum of the file
# Description    : This function will calculate the md5sum (checksum) of the file and return it.
# Created By    : Rinkesh Bansal
#
sub md5sum($)
{
    my $file = shift;
    die "Error::File ($file) does not exist!!!"    if (not -e $file);
    open (FO, $file);
    binmode(FO);
    my $md5 = Digest::MD5->new;
    while ()
    {
        $md5->add($_);
    }
    close(FO);
    my $checksum = $md5->hexdigest;
#    print "$checksum $file\n";
    return $checksum;
}

Clearing a screen

# Function Name    : clear_scr
# Input            : none
# Output        : none
# Description    : This funtion will clear the screen
# Created By    : Rinkesh Bansal
#
sub clear_scr()
{
    my $os = $^O;
    if ($os eq "MSWin32")
    {
        system 'cls';
    }
    else
    {
        system 'clear';
    }
}

copying a file

use File::Copy; # include this perl module in your program to make this function work

# Function Name : copyFile
# Input            : Source & Destination Location
# Output        : none
# Description    : This function will copy given source file to destination location.
# Created By    : Rinkesh Bansal
#
sub copyFile($$)
{
    my ($source, $target) = @_;
    if (-e $source)
    {
        my $targetdir;
        if (substr($target, -1) eq "/")
        {
            $targetdir = $target;
        }
        else
        {
            $targetdir = substr ($target, 0, rindex($target, "/"));
        }

        copy ($source, $target);
    }
}

logger functionality to create backup of files

# Function Name : backup_result_file
# Input            : Number of backups, Name of the result file
# Output        : none
# Description    : This function will create backup of result file. Max number of backups handle are passed as first parameter
# Created By    : Rinkesh Bansal
#
sub backup_result_file($$)
{
    my ($num_of_backup, $result_file) = @_;

    for (my $i = $num_of_backup - 2; $i > 0; $i--)
    {
        my $temp = $i + 1;
        my $source = "${result_file}.${i}";
        my $target = "${result_file}.${temp}";
        &copyFile($source, $target);
    }
    my $source = "${result_file}";
    my $target = "${result_file}.1";
    &copyFile($source, $target);
    unlink($source);
}

Sunday, September 25, 2011

Perl function to get Date and Time in required format

# Function Name    : getDateTime
# Input            : Time in epoch or it could be empty.  In latter case, it would return current date and time.
# Output        : current time in dd-mm-yyyy hh:mm:sec format.
# Description    : This function returns current date and time in above given format.
# Created By    : Rinkesh Bansal
# Date            : 25-Sep-2011
#
sub getDateTime($)
{
    my ($input) = @_;
    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst);

    if (trim($input) eq "")
    {
        ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
    }
    else
    {
        ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($input);
    }

    $mon = $mon+1;
    $year = $year + 1900;

    $mday = (length($mday) eq 1)?0 . $mday:$mday;
    $mon = (length($mon) eq 1)?0 . $mon:$mon;
    $hour = (length($hour) eq 1)?0 . $hour:$hour;
    $min = (length($min) eq 1)?0 . $min:$min;
    $sec = (length($sec) eq 1)?0 . $sec:$sec;

    return "$mday-$mon-$year $hour:$min:$sec"; // change this line to change the format you like it to return
}

Thursday, September 8, 2011

Running Netmeeting on Windows 7 box

Hi Everyone,

As you may have noticed that Windows-7 doesn't allow netmeeting.  But many users (like me) wanted netmeeting badly.  Follow below steps to make netmeeting work.

- Download and install Windows Virtual PC (approx 29 MB) and  Windows XP Mode (approx 470 MB) from
http://www.microsoft.com/windows/virtual-pc/download.aspx

- Install Windows Virtual PC

- Install Windows XP mode

- Launch Windows XP mode

- Login to it

- Run netmeeting as usual

- if you want to share your desktop (only screens of virtual pc not windows 7) then follow below steps
  • Close NetMeeting
  • Select "Disable integration Features" from the "Tools" menu
  • Launch NetMeeting again 
- Enjoy

Note:  There is one catch here.  You cannot share the desktop of your Windows-7, only desktop of your virtual PC will be shown. 

Tuesday, August 9, 2011

Transferring display of non-windows machine using Putty and X-Manager

Pre-requisites
1. Download and Install Putty.exe.  Latest putty can be downloaded from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
2. Doiwnload and Install XManager 2.0 or above.  XManager can be downloaded from http://download.cnet.com/Xmanager/3000-7240_4-10038129.html

Steps you need to follow
1. Go to Start->Programs->Xmanager2->Xmanager - Passive
2. Launch Putty and load/provide the IP of the machine you wanted to connect
3. Goto SSH->X11->Enable X11 forwarding
4. Click Open
5. Set Display environment variable by using below command

    export DISPLAY=:0.0
 6. Test if display is transferred by using xclock command

Note: This will work only if host is having SSH.