Notes

Uninstall Perl Module

Here’s how to cleanly uninstall any Perl module:

#!/usr/local/bin/perl

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

$ARGV[0] or die "Usage: $0 Module::Namen";

my $mod = $ARGV[0];

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

foreach my $item (sort($inst->files($mod))) {
         print "removing $itemn";
         unlink $item;
}

my $packfile = $inst->packlist($mod)->packlist_file();
print "removing $packfilen";
unlink $packfile;

Find Out the Top 10 CPU Hogs

I found this command useful in finding out which top 10 processes are hogging my CPU resources. Note that this command is specific to the Red Hat flavor of Linux. See the man page for ps for the correct output format to use for your specific platform:

ps -eo pcpu,pid,user,args | sort -k1 -r | head -11

Substitue pcpu above with pmem to see the memory hogs instead.

Bourne Shell Logging Routine

Here’s another logging routine, this one is written in Bourne shell:

#!/bin/sh

log_message() {
    echo `date "+%m/%d/%y %H:%M:%S %Z"` "$1" | tee -a aaa.out
}

log_message "Hello there"
log_message "Goodbye"

Sample output:

08/28/07 23:16:13 EDT Hello there
08/28/07 23:16:13 EDT Goodbye

 

Setting MySQL Password

To set up root password the first time:

$ mysqladmin -u root password NeWPasSwORd

To change an existing root password:

$ mysqladmin -u root -p oldpassword newpass
Enter password:

To change a normal user password:

$ mysqladmin -u dbuser-p oldpassword newpass

Sorting IP Addresses

The following will sort an array of IP addresses in @in and the sorted IP addresses will be in @out.

@out = sort {
    pack('C4' => $a =~ /(d+).(d+).(d+).(d+)/)
    cmp
    pack('C4' => $b =~ /(d+).(d+).(d+).(d+)/)
} @in;

What this does is it forms a string of four bytes out the IP address octet using the pack() function then sorts it lexicographically.

See also Sorting Section Numbers