Thursday, August 30, 2012

I haven't ever heard about open source Search Engine kinda thingy...... :P

Came around this:
The Apache Lucene project develops open-source search software
Apache Lucene
NOOP operator in Bash:

A standard NOOP Operator in bash is colon ":".

Try out:
: echo test or anything :)
[m@root]$ a=1
[m@root]$ b=2
[m@root]$ c=3
[m@root]$ echo $a; : echo $b ; echo $c
1
3


Thanks,
Kailash Chandak

Wednesday, August 29, 2012

Reference Counting Garbage Collection and Circular Reference in PERL

Found very good link about Memory Management in PERL:

http://www.perl.com/pub/2002/08/07/proxyobject.html

Tuesday, August 28, 2012

Wednesday, August 22, 2012

How to identify driver for a give network interface card.


$/sbin/ethtool -i eth0
 
where,
eth0 : Name of Network interface card. 

Tuesday, July 24, 2012

Remove duplicate entries in a perl scalar array

How to remove duplicate entries from perl scalar array.

Ans ==>
my @duplicate_entries = (1,2,3,4,3,22,45,1,22,76,456,12,45,22,876,456,847,14,6,365,7,4,33,5);
my (%hash,@result);
foreach my $x(@duplicate_entries){
    unless($hash{$x}){
        push(@result,$x);
        $hash{$x} = 1;
    }
}

>> @result will be an array of unique elements.

Write a program which will identify public IP address of the current host.

sub get_tm_ip {
    my($host_to_contact) = shift; < ---- it can be any 
                                      pingable hostname
                                      (e.g.  google.com )
    my($port) = 22;
    my $sock = IO::Socket::INET->new(
            PeerAddr=> $host_to_contact,
            PeerPort=> $port,
            Proto   => "tcp");
    my $localip = $sock->sockhost;
    return($localip);
}



Get unique id for a Linux host.

Sometimes we found hostid for two hosts are same. In this case, following command should help us to get unique id for a linux host.

[root@host ~]dmidecode|grep UUID|cut -d: -f2|tr -d ' '
420DE5AC-31FE-5A1A-DDA3-C971902A228D

Inserting column [with value] at a given position in a file using AWK [1 liner]

very useful:
awk -v FS='|' -v OFS='|' '{$3=$3"|"4} 1' 1.txt 

Input:
1|2|3|5 
1|2|3|5 
1|2|3|5 
1|2|3|5 

Output:
1|2|3|4|5 
1|2|3|4|5 
1|2|3|4|5 
1|2|3|4|5 

Wednesday, July 18, 2012

variables inside awk print and sed

Simple & useful: [Many times i forfot this trick]


[mandy ~]$ echo $v1
75

[mandy ~]$ awk -F "|" ' { print $'"$v1"' } ' file_name
mandar
mpande
mp

[mandy ~]$ sed 's/'"$old_val"'/'"$new_val"'/g' file_name

Monday, July 9, 2012

XML Pull Parser

Found a very good article/link in XML Parsing:

Need to check this PullXML Parser thing is available with Perl/Python ? 
This kind of parsing seems to be really faster, efficient than SAX [Off course faster/better than DOM :)].

 XML Pull Parser .
http://www.bearcave.com/software/java/xml/xmlpull.html

Tuesday, May 22, 2012

How to assign a file handle to a subroutine.
==============================

my $FH;
open($FH,"< /tmp/text");
my_print(\*$FH);
exit(0);
sub my_print {
    my $FH = shift;
    my @arr = <$FH>;
    print @arr;
}

Monday, May 21, 2012

More details on git and subversion integration :
http://metypefunny.blogspot.com/2009/01/git-it-together-with-subversion.html




Steps to create git repository on RHEL 5.x system :
 rpm -Uvh http://repo.webtatic.com/yum/centos/5/latest.rpm
 yum install --enablerepo=webtatic git-all
 git
 mkdir src
 cd src/
 git init
 cp ../savecmdlog.pl.bak savecmdlog.pl
 git
 git status
 git add savecmdlog.pl
 git commit
 git config --global user.name "Manas"
 git config --global user.email manas_khandeshe@symantec.com
 git commit --amend --reset-author
 git log
 git diff
 git commit -a -m 'hard coding of sql statements'

Tuesday, May 8, 2012

How to recover from GRUB not Found error :
http://searchenterpriselinux.techtarget.com/tip/Its-an-easy-fix-to-clean-up-a-GRUB-error-on-your-Linux-server?asrc=EM_NLN_17277113&track=NL-795&ad=870966&


Monday, May 7, 2012

validation for 5GB free space in shell for all platforms

Simple but very useful:

#-------------------------------
# Validation for 5GB free space.
#-------------------------------
#AIX OS
if [ `uname` = "AIX" ]
then
    if [ `df -g $op_path | awk ' { print $2 } ' | tail -1` -lt 5 ]
    then
        echo "Minimum of 5GB of free space should be presnt at $op_path to run the script"
        exit
    fi
fi
#HP-UX
if [ `uname` = "HP-UX" ]
then
    val=`bdf $op_path | awk ' { print $4 } ' | tail -1`
    val_gb1=`echo "scale=2; $val/1024" | bc`
    val_gb=`echo "scale=2; $val_gb1/1024" | bc`
    #if [ $val_gb \< 5 ]
    if [ $val_gb -lt 5 ]
    then
        echo "Minimum of 5GB of free space should be presnt at $op_path to run the script"
        exit
    fi
fi
#SunOS
if [ `uname` = "SunOS" ]
then
    val=`df -k $op_path | awk ' { print $4 } ' | tail -1`
    val_gb1=`echo "scale=2; $val/1024" | bc`
    val_gb=`echo "scale=2; $val_gb1/1024" | bc`
    #if [ $val_gb \< 5 ]
    if [ $val_gb -lt 5 ]
    then
        echo "Minimum of 5GB of free space should be presnt at $op_path to run the script"
        exit
    fi
fi
#Linux
if [ `uname` = "Linux" ]
then
    val=`df -k $op_path | awk ' { print $4 } ' | tail -1`
    val_gb1=`echo "scale=2; $val/1024" | bc`
    val_gb=`echo "scale=2; $val_gb1/1024" | bc`
    if [ $val_gb \< 5 ]
    then
        echo "Minimum of 5GB of free space should be presnt at $op_path to run the script"
        exit
    fi
fi

Monday, April 30, 2012

How to use "Like" and "In" together in MySQL ?

Simple and very useful:
SELECT * FROM tablename WHERE column LIKE 'M510%' OR column LIKE 'M615%' OR column LIKE 'M515%' OR column LIKE 'M612%';

Monday, April 16, 2012

Constructor overloading in Perl

Base Class:
-----------

#!/usr/bin/perl
use strict;
use Data::Dumper;

#write package name:
package Person;

#write constructor
sub new
{
#declare => hash & bless it and return it.
my($class)=shift;
my($self)={
        _name=>shift,
        _sname=>shift,
};
bless $self, $class;
return $self;
}

1;
 
Derived class:
--------------

#!/usr/bin/perl

#define package:
package Employee;

use strict;
use Data::Dumper;

#use parent class
use Person;

#Define ISA
our @ISA = qw(Person);

#Define constructor with child and parent both:
sub new
{
my($class)=@_;
my($self)=$class->SUPER::new($_[1],$_[2]);
$self->{_id} = $_[3];
$self->{_sal} = $_[4];

return ($self);
}

1;

Program:
--------

use strict;
use Data::Dumper;

use Person;
use Employee;

sub main
{
my($obj)=Employee->new("mandar","pande","111515","1");
print "$obj->{_name}\n";
print "$obj->{_sname}\n";
print "$obj->{_id}\n";
print "$obj->{_sal}\n";
}

main();

Multithreading in Perl

Found few good links with examples:

http://pages.swcp.com/~breadfan/threads/threads_shared.html

http://migo.sixbit.org/papers/Perl_Threads/slide-00.html