Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Linux Ask!

Mar 012010
 

How to remove install CPAN modules?

Answer:

1. Copy the script below, e.g. remove_module.pl

#!/usr/bin/perl -w 

use ExtUtils::Packlist; 
use ExtUtils::Installed; 

$ARGV[0] or die "Usage: $0 Module::Name\n"; 

my $module = $ARGV[0]; 

my $inst = ExtUtils::Installed->new(); 

foreach my $item (sort($inst->files($module))) { 
    print "Removing $item\n"; 
    unlink $item; 
} 

my $packfile = $inst->packlist($module)->packlist_file(); 
print "Removing $packfile\n"; 
unlink $packfile; 

2. Execute the script to remove module, e.g. MongoDB

# perl remove_module.pl MondoDB

Feb 262010
 

How to sort a file by n-column

Answer:

Suppose you have a CSV file:

1,c
2,d
3,a

How do you sort by the 2nd column?

Here is the command you need:

# sort -k2 input.txt -t ','

where -t ',' mean the comma separator, and -k2 mean the 2nd column.

Feb 252010
 

Change MySQL replication master host

Answer:

To change the MySQL replication master host from a MySQL slave, follow the steps below.

1. Copy current master bin log file name and position

mysql> STOP SLAVE;
mysql> SHOW SLAVE STATUS\G

You will find something like the following...

Master_Log_File: mysql-bin.000081
Read_Master_Log_Pos: 3684056824

2. Change to new master using command

mysql> CHANGE MASTER TO MASTER_HOST='192.168.1.2', MASTER_LOG_FILE='mysql-bin.000081', MASTER_LOG_POS=3684056824;
mysql> START SLAVE;