Skip to main content

Posts

Disable ssh timeout on client site

I think this is the nth time I Google for it, and look for the right result that solve this problem. Never have the solution stick in my mind. Keeping this for my own reference. :) Update /etc/ssh/ssh_config with this line : ServerAliveInterval 300 Reference : How to disable SSH timeout The reference said it works for Ubuntu (I personally tested) / Debian. I am setting this in CentOS, it works too. :)

CGI - Common Gateway Interface

What is the first thing come to your mind, when you see... CGI? Me -- Perl. But it's actually more than Perl. Here's some examples on CGI in different languages and some setups on Ubuntu to get the web server running. To setup Apache2 in Ubuntu. This will install and run the Apache2 server : sudo apt-get install apache2 By default, the cgi directory is setup at /usr/lib/cgi-bin . Just have your cgi scripts or executable put in this directory (make sure it's executable) and it can be access via http://localhost/cgi-bin/ path. This can be modified at the config file. The default config file is at /etc/apache2/sites-available/default . The section of the file that related to this looked like this : ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> The access and error log can be found at /var/log/a...

RCS - Revision Control System

I almost forgot about RCS! Keeping this for my future reference. This revision control system required minimum setup. What I need is just simply to have RCS installed. To install in Ubuntu : sudo apt-get install rcs To check-in your file : ci filename You will see a new file created in the same directory : filename,v And you'll wondering where your file is. To keep your file "visible", add the -u switch. ci -u filename To make it more organized, create a RCS directory in your working directory, so the ,v file will be stored in RCS directory. If you are using the ci without -u switch, you can use co command to checkout the file. co filename To check out and lock the file for edit, use the -l switch : co -l filename To do a diff with your changes and the last check-in version : rcsdiff filename To see the log and change summary of each check-in : rlog filename Some screenshots for the above mentioned commands.

Checking environment variable in shell scripts

Found couple of ways, the common one : My test scripts : #!/bin/sh if [ -n $JJ ] ; then echo "-n1" fi if [ -z $JJ ] ; then echo "-z1" fi JJ="" if [ -n $JJ ]; then echo "-n2" fi if [ -z $JJ ] ; then echo "-z2" fi JJ="jcrys26" if [ -n $JJ ]; then echo "-n3" fi if [ -z $JJ ]; then echo "-z3" fi The result is ... -n1 -z1 -n2 -z2 -n3 -z to test if a string is empty. -n to test is a string is not empty. What about if a string is undefined? And the result really confused me. I have checked the environment variable, I don't have one with name of "JJ". Reference : http://linuxcommand.org/wss0090.php Have kept this in draft for a long long time due to the -n result. So.... A quick conclusion is, use the -z . Use -n at your own risk. To revisit this next time, if I still remember. :P

"Rename" a user in Linux system

I tried this in Ubuntu 12.04 LTS. Run these commands as Root in a terminal. To change a user name. usermod -l<new_user_id> <old_user_id> To change the home directory usermod -m -d /home/<new_user_id> <new_user_id> The above 2 can be combined into a command. usermod -l <new_user_id> -m -d /home/<new_user_id> <old_user_id> * I didn't tried this though. :P Next, change the content of the following files. Edit the content by replacing <old_user_id> to <new_user_id> . /etc/hosts /etc/hostname What is next? Yes, the user name. This can be change via  User Accounts. Click on the upper right people icon and open the User Accounts GUI. The name can be changed via that interface. After logout, you'll see the new_user_id account is ready to be used. :) Note, if you are seeing error prompting unable to change the user_id, you'll need to login to the system as Root, not to use sudo su as Root. Refere...

Create cdb file using perl

To create cdb file in perl is quite easy when you have the hash ready. See example below. #!/usr/bin/perl use strict; use CDB_File; my %t = ( 'a' =>'apple', 'b' => 'banana', ); CDB_File::create %t, "<cdb file name>", "<temporary file name>"; If you have the key-value pairs in a file, you can parse through it and insert into the cdb by getting the hash ready, or by the pairs. Say your data file contain this. a,apple b,banana Perl code for getting this flat file data into cdb : #!/usr/bin/perl use strict; use CDB_File; my $cdb = new CDB_File("<cdb file name>", "<temporary file name>"); open (DATA, "<data file name>"); while (<DATA>) { chomp(); my @data = split /,/; $cdb->insert($data[0],$data[1]); } $cdb->finish;

Something about object files

This is from a long lost track. I used to deal with object files in my previous job. That was like ages ago. Is VCS still compiling the design into object files to run simulation? Anyway, thanks to Synopsys team that helped me a lot in improving my debugging skills. :) Some simple steps to create a "test case" here. Let's create a "Hello world!" object file. #include <stdio.h> void main() {     printf("Hello world!\n"); } Compile into object file. gcc < source code file name > -o < object file name > To enable debug mode, compile with -g option. With debug mode, you can set break point when running the program in gdb. OK, back to the story. These are a few commands that they taught me to investigate about the object files. To get the list of the functions in the object file. strings < object file > This one is not obvious in my test case. The strings command actually listed all the strings in the o...

Some sharings on Oracle database and MySQL database

Recently, I am getting involved a lot on database related tasks. My previous jobs mostly deal with gdbm and MySQL. This "new" job makes me deal a lot with Oracle database and cdb. :) I actually never bother to get to know the special tables in the database. I need to do a tiny query on production server to get to know the number of records of some of the tables today. Imagine a database with thousands of tables. I can't be doing select count(*) from <table name> for all of the table names. In addition, I don't know the list of the tables of interest but only the pattern of the table names. Luckily, found this post : http://stackoverflow.com/questions/6703444/counting-no-of-records-from-multiple-tables-oracle-db There is a special table host the tables information, namely ALL_TABLES . To get the list of tables in the database and number of rows for each table, run this sql statement in sqlplus. select TABLE_NAME, NUM_ROWS FROM ALL_TABLES; For MyS...

Accessing data in cdb file using Perl

See this post on cdb file related. Never knew this can be so easy, thanks to the contributors, see here . To install the library using cpan. Note, must use root to perform this as this will need the root access to create new file/directory. sudo cpan install CDB_File Say you have a cdb file created call abc.cdb with a key summer . Here's how you can get the value of the key summer . #!/usr/bin/perl use strict; use CDB_File; my $cdb = "abc.cdb"; my %hash; tie %hash,'CDB_File',$cdb or die("unable to tie to cdb file"); my $value = $hash{'summer'}; print "$value\n"; Please note, if a key is not found, it will return a null value. Without the CDB_File library, the tie will not work, and will have this error message : Can't locate object method "TIEHASH" via package "CDB_File" So, have fun! :)

Sending picture file in an email

It is easy to attach a picture in an email, from user's perspective, of course. But, what is actually sent over the Internet to the recipient server? There are 2 types how a picture can be transmitted over an email, as inline picture, or as an attachement. Before they are transfer over, they need to go through some conversion, that is binary-to-text encoding called Base64. Say, the binaries of the image starts with FF D8 FF , and the translation process can be as below : Original binaries FF   D8   FF Regroup the binaries 111111 111101 100011 111111 Associate decimal 62 61 35 63 From the Base64 index table / 9 j / Inline image To send as an inline, the email message shall have the following attributes. Content-Type: image/gif; name=" file name " Content-Transfer-Encoding: base64 X-Attachment-Id: image-id Content-ID: < image-id > Followed by the image binaries in Base64. The attributes and the image binaries is placed withi...