Sunday, April 29, 2007

Install Ubuntu 7.04

I took time during holiday to install Ubuntu 7.04 (code name Feisty) on my home computer. I thought for people with Unix background like myself, it should be simple exercise. It is not. My home computer is old Pentium IV 2.26 MHz, 768 MB RAM with installed Windows XP SP2 and I decided to install Ubuntu as guest OS on virtual machine using Vmware Workstation. First I used Vmware Workstation to create a machine with 6 GB Hard disk. Since Ubuntu is not on list of Vmware available guest OS, I just selected other Linux as guest OS for my virtual machine. I booted the virtual machine with fresh downloaded Ubuntu 7.04 and followed the instruction on the screen. The first installation got stuck at 69 %, I waited 10 minutes then reboot and try second attempt, that went well until completion. Now I can login using the account/password asked and created by installation program. My first impression is not bad, the screen looks nice on 1024x768 resolution, even sound card works. Pre-installed Firefox 2.0 work smoothly even on virtual machine, Ubuntu accepts an IP address assigned from my ADSL Internet modem automatically thus I got connection to Internet.
1. issue sudo: I want to install some additional software as root however what is password of my well known root?. After few minutes investigation, I recognized that Ubuntu using sudo as mechanism to allow normal account access to root and by default root is locked and no one can neither login as root nor su. To run program using root account, we have type e.g.
 
sudo shutdown -r +15 "quick reboot"
sudo will ask us to enter our password and then run shutdown using root account. I known that sudo mechanism is used also in Mac OSx 10.4 Tiger and it offers certain benefits against traditional root, however I can not change my habit so I unlock root account by enter
sudo passwd 
2. issue apt-get: I want to try ruby so I type in command line terminal
ruby
Ubuntu is intelligent enough to answer that ruby is not installed and offer me that I can install ruby by using
sudo apt-get install ruby
I tried and it works. The apt-get is Ubuntu package manager (now I know that it is from Debian and Ubuntu is rooted from Debian). It does all things: downloads required software including dependencies, installs and configures. If we does not know name of software package, then Synaptic Package Manager is application that offers features such as listing, installing and uninstalling software package. apt-get use configuration on /etc/apt/sources.list, which contains list of ftp servers storing debian distribution package.
After adding new repository into /etc/apt/sources.list, hit 'reload' button to get package information from the new added repository.
3. issue add path: I download and install SUN JDK 1.5.0_11 and want to add JDK 1.5 to PATH so I can type java, javac, etc. I created .bash_profile in home directory and add two following line
export JDK_HOME=~/jdk1.5.0_11
export PATH=~/jdk1.5.0_11/bin:$PATH
and do logout/login, it doesn't work. I tried to put these line to .xssesion, after that I can't login to the system anymore and have to login using failsafe session to remove this .xsession file. Looking at documentation and even googling doesn't help. At the end I realized that I should add these line at the end of .bashrc. Then it works in both cases either I login using X-Desktop or terminal using Windows putty.
4. issue Vmware tools: we can not install Vmware tools using Vmware provided package, the Feisty kernel version simply does not match. However Ubuntu provides its own vmware tool package. Installation is pretty simple, just type
uname -a
to get kernel version, my kernel version is 2.6.20-15 and then invoke apt-get
 
sudo apt-get install vmware-tools-kernel-modules-2.6.20-15
Finally reboot to take effect. To be honest, I have not observed better response from any application as Vmware claimed.
5. issue update time: To keep your clock synchronized, install ntpdate package as follows
sudo apt-get install ntpdate
sudo /etc/network/if-up.d/ntpdate
sudo crontab -e 
@hourly /etc/network/if-up.d/ntpdate
6. issue missing c-header files: Ubuntu striped down in order to keep installation CD small and installation process fast. The result is default installation does not contain packages that developers normally expect. I got into trouble when I tried to compile a c program, gcc told me that file dlfcn.h is missing. I guested that some lib is missing but can not figure out which package contains the file. After spending time on Google, I found Ubuntu Package Web Site, where I can enter file name and search for package containing that file.

Monday, April 16, 2007

Create boot image in AIX

To create boot image e.g. on hdisk2 just type
# bosboot -a -d hdisk2 --> update the boot image information
# bootlist -m normal -o hdisk0 hdisk2  --> create a new bootlist
# bosboot -a  -->  update the boot image information
# bootlist -m normal -o  --> verify the bootlist is correct

Saturday, April 14, 2007

Oracle import

I was asked by a colleague, how to import an oracle dump file, that was exported from customer production site without data. Someone may think that it is stupid to write about this trivial task. However it is not so simple. In order to provide support for production database, we sometime have to export customer database without data and then import the exported file containing only schema and store procedure into our developer sandbox for testing purpose. The problem is that when import, Oracle try to create table and allocate data segment on disk with the same size as in the production database. Our developer sandbox of couse does not have capacity as customer production machine, so the import process often fails. Solution to this problem is perform import process into 3 steps. In Step 1, we create table and index creation file using e.g.
$imp userid=system/manager@test file=exp-code.dmp full=yes indexfile=create-schema.sql
This will create create-schema.sql that contains tables and index creation commands. With little effort, using any text editor, we can modify this file to remove segment size parameter of each command and save it as create-schema-small.sql. In Step 2, we run modified create-schema-small.sql against test database to create tables and indexes
$sqlplus scott/tiger@test @create-schema-small.sql
In Step 3, we run normal import with ignore error option, so Oracle will create store procedures and others required metadata.
$imp userid=system/manager@test full=yes file=exp-code.dmp ignore=yes
After reading, other colleague points out that in Oracle 10g, Oracle provide other tools expdp and impdp that can handle the above mentioned problem.

Thursday, April 12, 2007

Soft Coding

I have read the soft coding article recently. Based on my own experience I have a sympathy to the hard coding approach. However I think the problem is not about whether soft coding or hard coding, but programmers including myself try rigidly to follow the soft coding approach believing that it will result in more flexible code, which is not true in most cases.

Sunday, April 8, 2007

Using Regexp

I got a task to parse file consisting of SQL commands and various noisy lines including empty, comment and echo. I decided to use ruby String::scan to extract SQL commands from files. The only problem is how to write an correct regexp. I started with some test
entire=<<-EOF
create table A(id number)
/
create table B(id number)
/
EOF

entire.scan(/create table.*\//) #=>[]
I passed to String::scan a regexp that represents a String starting with 'create table' following by any number of characters and ending with '/'. But there is something wrong instead of
=> ["create table A(id number)\n/", "create table B(id number)\n/"]
I got a empty array
=>[]
I have looked at documentation, tried different alternatives without success. Then I picked the book Mastering Regular Expressions and read the chapter. It is immediately clear to me, instead of using '.' as any character, I should use [^\/] mean any character different from '/'. The correct usage of regexp is
entire.scan(/create table[^\/]*\//) 
#=> ["create table A(id number)\n/", "create table B(id number)\n/"]
In order to support multi-line and avoid case sensitive, I just add two options 'm' and 'i' to the regexp
entire.scan(/create table[^\/]*\//im) 

Monday, April 2, 2007

Using Ruby and Rails with Oracle database

1. Download ruby-oci8-VERSION-mswin32.rb 2. Install oci8 adapter e.g. on MS Windows
c:\ruby ruby-oci8-VERSION-mswin32.rb
3. Using with with Rails
ActiveRecord::Base.establish_connection(
 :adapter => "oci",
 :host => "sql_net_connect_string",
 :username => "foo",
 :password => "bar"
)

AIX varyon volume group in multi nodes environment

On environment with multi-nodes running AIX accessing single share fiber channel storage, I am facing a problem, if one node fails, I can not import volume group residing on that physical disk in an other surviving node, although physical volume owned by that node is accessible from surviving node. OS gives out a error can not access volume group descriptor. It make me crazy, because one reason, why I need expensive fiber channel storage is to have flexibility to access volume group of failure node from surviving node. It takes me a while to figure out how it works. When AIX activate volume group, it places a lock on corresponding physical volume, so other node can not activate this volume group. The varyon command always checks the physical volume and refuses to activate that volume group if it is locked by other. It does not matter if the locking node is still living or death. In order to release the lock, we should issue on locking node
varyon -b volume_group_name 
This '-b' flag breaks disk reservations on disks locked as a result of a normal varyonvg command. Because this flag only works on volume group that is already varied on, we should do it on a node that originally owns this volume group to make sure that if that node fails, other can activate the volume group.

Sunday, April 1, 2007

Writing an Use Story

Having Use Story is first step of software development cycle. How to effectively write an good, concise Use Story is challenging task of business analyst. I have found quite good guideline on that topic on Dan North What is Story