2006/08/31

Run Perl script in a CGI script

The backtick opeartor can place a well-done Perl script in a CGI script. But a CGI script running on the web usually use a standard library:

/usr/lib/perl5/5.8.0

problem:
If that well-done Perl script use non-standard library in a specifical Path, you may get below error:

Can't locate XML/Xerces.pm in @INC ...


Solution:
Add a path to that non-standard library in the CGI script.

use lib '/usr/local/hive/lib/.....'

'export LD_LIBRARY_PATH=/usr/local/....:${LD_LIBRARY_PATH}'

2006/08/29

File permission in *nix

To access child directory, the parent directory at least set to be executable.
For example:

/home/user1 ---- set to 7 - -
/home/user1/public_html ---- set to 7 5 5

In order to let other user access public_html of user1, permission of /home/user1 must be changed to 711 at least.

Note: setting a folder’s permission to 711, other user cannot read this folder (list the folder to see what files inside), but the readable file in that folder can be reached if other user knows file’s name.

2006/08/24

@INC

@INC is a special Perl variable which is the equivalent of the shell's PATH variable. Whereas PATH contains a list of directories to search for executables, @INC contains a list of directories from which Perl modules and libraries can be loaded.

When you use(), require() or do() a filename or a module, Perl gets a list of directories from the @INC variable and searches them for the file it was requested to load. If the file that you want to load is not located in one of the listed directories, you have to tell Perl where to find the file. You can either provide a path relative to one of the directories in @INC, or you can provide the full path to the file.

Source: http://perl.apache.org/docs/general/perl_reference/perl_reference.html#Description

Note: use
perl -e 'print join "\n", @INC'

to check what pathes have been defined, but it does not show the all pathes which being used.

.bash_profile VS. /etc/profile

The global /etc/profile and your own local ~/.bash_profile are read when the shell is invoked as an interactive login shell, for example when you open a remote terminal session to someone else's machine, or when you log into your own machine without X Windows running, or when you hit ctrl-alt-F1 from X Windows to start a virtual terminal session.

The global /etc/bashrc (if it exists) and your own local ~/.bashrc is read when the shell is invoked as an interactive non-login shell, for example when you open up a terminal window in Gnome or KDE.

So you will be wanting modify /etc/bashrc if you want to the setting for all users, or in your ~/.bashrc if it's just for you.

Source: http://www.experts-exchange.com/Operating_Systems/Linux/Q_20895782.html

2006/08/21

Set up public_html and CGI

By default, http://exaple.com will be translated to the file path '/var/www/index.html' or default apache page if index.html does not exist. Also, all files in ‘/var/www/cgi-bin’ will be reconginzed as being eligible for execution rather than process as normal document, no matter the file name (in the other word, the file can be ‘anyname.anyexten’).

Of course, the ordinary user can also have 'http' and 'cgi' supported. Just follow the below steps:

Prerequisites:
1. You must have ‘root’ privilege
2. Apache has been installed and started, in my machine I use following commands to check

/usr/sbin/httpd status (check the Apache status)
/usr/sbin/httpd –h (help file of httpd command)


Step one: create public_html and cgi-bin at a user’s home directory, change mods to 755

Step two: edit server configuration file, in my machine it is ‘/etc/httpd/conf/httpd.conf’

vi /etc/httpd/conf/httpd.conf

a. Set the file path with UserDir

UserDir public_html

b. Enable a cgi directory for a user

<Directory /home/*/public_html/cgi-bin/>
Options ExecCGI
SetHandler cgi-script
</Directory>

You can see http://httpd.apache.org/docs/2.0/howto/public_html.html for detail.

IMPORTANT:
You need to restart Apache to invoke the change. I use below command:

/usr/sbin/httpd - k restart

NOTE:
1. Every file in cgi-bin will be executed as a script, every file in public_html will be executed as normal documents
2. Don’t need to change other perameter in httpd.conf, which you may think need to be changed, such as ‘AddHandler cgi-script .cgi’, ect. I will explain how to use them in next.

OK! Now it is the time to write a simple html file, for example index.html, in public_html, and write a simple cig/perl file in cgi-bin you created before. Set permission of those files to 755. You should be able to run them from browser.

You may want to run script everywhere instead of the scripts in cgi-bin. You can do this by following steps:

Step one: edit server configuration file.

vi /etc/httpd/conf/httpd.conf

Add a line, or just move the ‘#”,

Addhandler cgi-script .cgi .pl

.cgi and .pl means the file with those extention will be executed as script

Step two: search for the line that says "<directory>" in the file. It should look something like this:

<Directory>
Options FollowSymLinks
AllowOverride None
<Directory/>


Add "+ExecCGI" to the options list. The line now looks like this:

Options FollowSymLinks +ExecCGI

Note:
1. You need to restart Apache to invoke the change.
2. Doing this does not affect the file in cgi-bin. In the other word, every file in cgi-bin is still treated as scripts no matter what file extension.
3. When you find the problem, you can check the error logs by

cat /var/log/httpd/error_log

Check your linux's version

I remotely connet (SSH) to Linux Develop Box everyday. Sometime I need to check what the version of Linux OS I am using from command line. Here it is:

cat /proc/version

2006/08/20

Time vs. Money

"Time is Money" is one of most famous wisdoms. It seems to be a real no brainer - even a little kid can figure out. Our income is counted by time, either annuual salary or timerate payment.

To earn money you must spend time, which is the same to everyone. Only different is that how much you will get for spending the same amount of time. Therefore, the very important thing is that how to use your time efficiently. This is not a easy question. I believe people who can controls his/her time must be smart and rich.

Everybody has 24 hour per day. It seems like you cannot spend every second on earning money. On the contrary, it seems you often spend money on killing time. However everyone need good rest after hard working, therefore, You enjoy time by spending money is actually for earning money.

"Time is Money". So don't waste time, but master time. Unfortunately, it is no so easy :(

P.S. I spent a lot of time on finding a cheap and good frame glasses in the past few days. Finally, I go back to my initial decision. SIGN! IS IT NECESSARY?
DON'T BE SO PICKY!
DON'T BE SO VACILLATED!

2006/08/18

Dell Battery Recall

As you may be aware, Dell Corp. has recently discovered that a large number of notebook betteries carry a malfunction risk. Now Dell starts bettery recall program, which gives me a feeling that Dell is a great company for his service.

My company's laptops are all bought from Dell. The one I am using now is Dell Latitude D610. I received the note this morning to visit Dell Bettery Return Programm Web to identify whether or not an at-risk battery is installed in my unit.

There are two steps to identify:
1. Model
2. PPID (Dell Part Piece Identification)
My battery was passed at first step check since it is made in Korea. As I know none of my colleagues' batteries needs change.:)

I heard of many negative feedbacks for Dell product's quality. I did not have any Dell's product until I got this D610 from my company. It works great which let me want to try more Dell's products. I even decided to sell my TOSHIBA notebook replaced with a Dell Desktop.

Hopefully, this Battery Storm will not give Dell too much hit. I believe a lot of people like me are expecting a good deal from Dell.

2006/08/17

Load searches from FF search bar in new tab

Step 1:
download and install this handy extention, 'tabbrowser perferences'

Step 2:
restart firefox

Step 3:
goto
Tools -> Options -> Tabbed Browsing -> User Interface
select the box, ‘Searches from the search bar’

@ARGV

@ARGV is predefined variable to hold the command line arguments.
$#ARGV is the totoal number of arguments minus 1.
$ARGV[0] is the first argument.

For example:

perl test.pl one two three


@ARGV --> ("one", "two", "three")
$#ARGV --> 2
$ARGV[0] --> one

Comcast cable

I found my home high speed internet became very slow in this two day. At the beginning, I thought it may be a problem from my router. (I got this kind of problem before -- reset the router, get back the speed.) But this time I was not luck. I used speakeasy to test the speed. The download was normal around 6000 kbps, but the upload testing was stuck there for a long while.

The Comcast representative I speak to is very nice. He tried to help me starting from the simple network connection check to a little bit professional check at command line. He believed that the Comcast’s Servers was fine, the problem was from some other Hops where every connection need to pass.

I hope it was just network congestion at somewhere, and will be clear at sometime.

PS: one command I learned from Comcast guy:

tracert yahoo.com

It will show you how many Hops (intermediate routers) the connection must pass through to get to yahoo sever from your computer.

2006/08/16

A long string

To define a variable in Perl is pretty simple. A variable preceded with $ can present number, string, etc. When we want to present a long string, in order to avoid being misinterpreted we need put '\' to skip some charactor such as '%','%' ect.

One simple way is using a subroutine like below, but it cannot handle '@'.


sub GetLongString {
return << "LONG";
WHATEVER $%!~(*&^)(
LONG
}