*NIX

How to redirect url permanently in Apache

One day you may want to rename your domain name to a new one due to inappropriate use of the old domain. However, the old domain is still valid and still valuable for search engines. It is possible to redirect all existing urls to the new domain gracefully. For example, http://abc.com/node/8 to http://def.com/node/8. Whenever one tries to access http://abc.com/node/8, webbrowser will be automatically redirected to http://def.com/node/8. This behavior also applies to search engines.

The trick is to use mod_rewrite in Apache HTTP Server

How to convert DVD video structure to AVI using Mencoder

Sometimes I have videos in DVD structure. It is a suitable format for burning to DVD disc directly. However, I don't want this high quality format. AVI is enough to reduce disk space usage. My tool is Mencoder again.

How to sniff TCP connection in Linux

Today I have to investigate network related problem that caused some networks were usable for a moment. This problem was occurring at remote site so I didn't have physical access to anything. What I have is just an account on the Linux router for the NAT network in training room. The application relies on web services technology so it is absolutely pure TCP. There are so many problem regarding this investigation. The coordinator don't understand the lower level of network so I can't ask too much information. Actually, I have to try by myself. At a glance, I would like to know if the connection from the client to the web services container is success or not. So I need to have a kind of sniffer.

How to install oci8 for PHP 5 on Ubuntu

OCI8 is an extension for providing APIs to Oracle database management system. However, installing OCI8 is not just easy like apt-get since it requires SDK offered by Oracle and its distribution license prohibits the inclusion to linux distribution. That means we have to download and compile it by ourselves. Fortunately, it is a little bit easy for Ubuntu.

How to measure memory consumption of a program on Linux

According to the hard fight which is a comparison of Java, Python and Ruby side by side, the performance is very impressive because Python is faster than the rest. A java guru immediately identified flaws of this test in Java codes. In addition, he also improved the codes for getting faster program. However, he was too busy to perform the benchmarks again himself. I volunteered to do this task on my laptop. After preparing all codes in Java, Python and Ruby, I have to measure how long it takes to execute each code. The tool I used was "time". Everything went well until I was asked to also measure memory consumption in each case. time always gave me zero without any error message. It seems this is a bug in Linux kernel that getrusage() will return zero in all memory related values. Fortunately, I found a workaround using Python!

How to forward port in user space using socat

I was asked to help setting up a kind of traffic redirection through VPN. In particular, the VPN server is Cisco VPN so the client should be Cisco VPN client too. Since the client is Ubuntu Edgy, it is very easy to install and run cvpnd. Then I tried to forward a TCP port to another host on the same port using IPTables and DNAT. Unfortunately, it failed. Incoming TCP connection through this port always get "connection refused". I guess that the problem might involve the module cisco_ipsec. This module may hook packet routing somewhere in the kernel so DNAT will not work correctly through its network interface. However, I don't have enough to investigate deeper for more detail since the service must be available tonight. In other words, I have 15 minutes left. So I decided to use port forwarding tool running on user space instead. After searching for a while, I found socat. socat looks like an extension of netcat which provides extremely flexibility to all of us for forwarding anything and then redirect to anything.