Wednesday, March 25, 2009

Use Expect script with Database and others

Expect is the tool for automated interactive programming, and it is available for Unix/Linux, Mac, and Windows.

If you are running a command line program and want to insert, modify, or retrieve data in and out with the database, expect is the choice.

It's simple and easy to learn and use. The basic commands are expect and send. Following is a piece of code to access MySQL database with Expect script.

set passwrd something
spawn mysql -u uid -p
expect "password:"
send "$passwrd\r"
expect "mysql>"
send "use CustomerDB\r"
expect "mysql>"
send "show tables;\r"
expect "mysql>"
send "select * from Customers where City = 'New York';\r"
expect "mysql>"
send "quit\r"

However, the expect script also can be used for Oracle but it is not limited to the database application. You can use it in other interactive applications such as ftp, telnet, and software installation, and software testing, etc.

Please check Don Libes' book Exploring Expect from O'Reilly for more details.

Use mkisofs to create data DVD for Unix file system

The popular DVD burning software for Windows like Nero and Easy Media Creator are not safe to burn the Unix file system directly on CD or DVD. If you burned a disc in this way, try to md5 files on disc and the original files. You may realize that some of the MD5 hashes are not identical!

The older version of mkisofs could not create the image file larger than 2GB. However, the current version fix this problem by using a new -UDF option. Following is the syntax to create a data DVD ISO image file for the entire dirname folder:

mkisofs -o file.iso -UDF -f -a -J -r -v -V "Volume ID" dirname

It's safe to burn the image file with mkisofs because all files on disc will be identical to the original files.

For more detailed options, please look at its man page or run "mkisofs -help".

Saturday, March 21, 2009

Unix sort command

The sort command has -u option for unique. Therefore, the command "sort file | uniq" can be simplified as "sort -u file".

To sort in arithmetic order, use -n option, and -r option is used for reverse order.

Don't forget to redirect standard error for debugging

Some programs print the error messages to the standard error instead of standard output. The trick is on a computer system, they both show up on the screen.

If you redirect the program's output to a file then examine the file later for troubleshooting, you may not find any error in the file. Most likely you run following from the command line.

cmd > file

The above command line only redirect the standard output to the file. To redirect both standard output and standard error to the file, run the following from the command line.

cmd > file 2>&1

Friday, March 20, 2009

IE blocks the ActiveX component installation

Some times IE blocks the ActiveX component installation for the security reason. If the component is trusted, you may need to temporary change the security settings of IE, then change the settings back after the component get installed. See the following for details.

From the IE, select Tools->Internet Options->Security. At the Security level for this zone, select Custom level. Look for ActiveX controls and plug-ins section, enable Download unsigned ActiveX controls, and look for Miscellaneous section, enable Installation of desktop items.

After the component gets installed. reverse above settings.

Monday, March 16, 2009

Install VMware View Open Client on CentOS 5.2

To install the VMware View Open Client, download the current version of rpm file from, then install it on the system.

1. download VMware-view-open-client-2.1.1-153227.i386.rpm from the above location.

2. Install rdesktop if the package hasn't been installed.

yum install rdesktop

3. Install VMware View Open Client.

rpm -Uvh VMware-view-open-client-2.1.1-153227.i386.rpm

The VMware View Open Client will be in the Internet group.

Install wireshark on CentOS 5.2

To install wireshark run the following as root:

yum install wireshark

Thursday, March 12, 2009

Install Ruby on CentOS 5.2

To install Ruby and related run the following as root:

yum install -y ruby
yum install -y ruby-devel ruby-docs ruby-ri ruby-irb ruby-rdo

Friday, March 6, 2009

PHP and Form

PHP handles variable and upload file in HTML form differently.

1. For Variable:

Following is an example form in a HTML page that uses variable.php to process the form.

<FORM method="POST" action="variable.php">
<INPUT type="text" name="variable">
<INPUT type="submit" name="submit" value="Submit Name">

In the PHP script, variable.php, $_POST['variable'] will keep the value of the variable that user entered in the above form.

2. For File:

Following is an example form to upload a file from the HTML page.

<FORM enctype="multipart/form-data" method="POST" action="file.php">
<INPUT type="file" name="file" size="30">
<INPUT type="submit" name="submit" value="Upload File">

In the file.php script $_FILES will keep all information about the file, and details are shown below.

$_FILES['file']['name'] - The file name.
$_FILES['file']['tmp_name'] - The file name with the full path.
$_FILES['file']['size'] - The file size in Byte.
$_FILES['file']['type'] - The Mime type of the file.

Using above information, the PHP script can save the file to the file system or insert the file name with full path or content of the file into the MySQL database.