Using Top Efficiently

March 30, 2006

Here is a link disussuing using TOP to create performance snapshots and other tips.


PERL for search and replace

March 16, 2006

You can use PERL as a stream editor to replace strings in one or more files in a directory like this:

perl -pi.orig -e ‘s/bgcolor=#ffffff/bgcolor=#000000/i’ *.html

The above replaces the color white with black in all html files in this directory and saves the original files with .orig extension.

Keep local environment when logging to remote servers

March 15, 2006

Use the script from O’Reilley.


if [ -z "$1" ]; then
echo "Usage: `basename $0` hostname"

cd ~/.skel
tar zhcf - . | ssh $1 "tar zpvxf -"

Read link for more info...

Generate SSL Certificate

March 15, 2006

Need OpenSSL for this –

openssl genrsa 512/1024
openssl req -new -key

Enter country, state, locality, org name, org unit, comon name, and email when asked. Note: Common Name is

openssl -req -x509 -key -in

Apache Tweaks

March 15, 2006

Avoid truncated filenames in log by editing httpd.conf:
IndexOptions FancyIndexing NameWidth=*

Here is a handy Perl script to compress all Apache logs automatically called LogFlume.

Serve an additional site under same DocumentRoot:

Add new Virtual Host:

DocumentRoot /home/www/htdocs #same as other site
RewriteEngine On
RewriteRule ^/$ /home/www/htdocs/newsite/index.html
RewriteRule ^/index.html$ /home/www/htdocs/newsite/index.html

Apache Toolbox

March 15, 2006

When installing Apache, check out Apache Toolbox and this article/script.

Restore single MySQL table from large DB dump

March 15, 2006

Here’s how to restore one or more tables from a full database archive. It assumes you used mysqldump to save the database and stored it in a gz file. First create the file

#!/usr/bin/perl -wn
BEGIN { $table = shift @ARGV }
print if /^create table $table\b/io .. /^create table (?!$table)\b/io;

Then do the following to restore the table:

zcat /path/ | extract-table Mytable> ~/Mytable.dump
mysql  mydatabase -e "drop table Mytable"
mysql mydatabase