Friday, November 7, 2008

Embed flash in html using javascript

Now a days Web applications embedding flash or video to describe about the stuff. I was came across the scenario where i have to embed flash in my web application.

I found that using javascript is better option.

Find the complete code in the following URL.

This is plain HTML document. One thing you have to take care is source file path. In above URL's document, you could find ####### symbol inside of the body tag.

You have to just replace ####### with your flash file absolute path.
for example...
/home/JP/demo.swf is name of the flash file. ###### should be replace with /home/JP/demo

Have fun.

Thursday, October 9, 2008

mysql replication

While working in application deployment you might have come across the term called "failover database". That means if any hardware problem in the DB server we can't access the database at all. So we have one more DB server to manage the application. When DB1 have some problem we can manage using DB2.

So to achieve this what i thought was have to take mysqldump and import to second server periodically. But there is the better facility in mysql 5.x version called "mysql replication". But mysql 5.1.x is stable for mysql replication. What mysql replication doing is simply coping the mysql-bin log from source DB server to detination DB server. whenever we do any transaction that will be logged in mysql-bin log. So coping mysql-bin log from one machine to another is the soluction for failover database problem.

For mysql replication just we need to change some configuration in my.cnf file.

you can find this file using the following command

find . | grep my.cnf

i) Edit the my.cnf file in server1[uncomment the line server-id = 1 by default commented]
server-id = 1

ii) Edit the my.cnf file in server2 [Uncomment the following entries and give proper values]
server-id = 2

master-host =
master-user = repl
master-password = password
log-bin = mysql-bin


master-host : DB server1 IP address.
master-user : this user should have all privileges. While create this user use the follwoing command to grant permission.
GRANT ALL PRIVILEGES ON *.* TO 'user'@'host'
IDENTIFIED BY 'some_pass';
master-password: password of the master-user

iii) Restart the mysql server using the following command

/etc/init.d/mysql restart

Whenever we do data manipulation both server will have same data and in sync. Now failover database is ready. This is the way to do mysql replication.

Thursday, October 2, 2008

Synchronize directories/files between servers

I came across the scenario where, we have to synchronize files and directories between different servers. For example[Refer image1] my application update images in server1 only. But the same image shoule be synchronized in server2 also.

There is tool 'Rsync' for linux to acheive this scenario.
Install Rsync in two servers. We are going to sync server1 with server2. So here destination server is server2.

In server2 add the following configration files.

i) Create rsync.conf file in /etc/rsync.conf
Add the following code given in between two lines in this file.
motd file = /etc/rsyncd.motd
log file = /var/log/rsyncd.log
pid file = /var/run/
lock file = /var/run/rsync.lock

path = /var/www/html/images
comment = Image Server
uid = apache
gid = apache
read only = no
list = yes

First four lines are log,pid,lock and motd files path

[thumbnails] is the label. This will refered in server1 to send the directories to server2.
path is the place where the directories and files will get stored.

ii) Create rsyncd.motd file in /ect/rsyncd.motd

Add some text. This will shown at the time of sync.
For expample add text like in between two lines.
File transfering.........

iii) By default rsync is disabled. So we have to enable Rsync. You can edit the file /etc/xinetd.d/rsync and chage the line as disable = no [by default disable = yes]

iv) Start the rsync server
/etc/init.d/xinetd start
Server2 [Destination server] configuration over.

In server1, only one line command will sync the file or directories to server2.

rsync -rptgou /absolute path/images

rsync ==> is the command
-rptgou ===> is the options
/absolute path/images ===> images is the directory we are going to transfer to server2 ===> this is the server2 ip and thumbnails is the lable we have added in "rsync.conf" configuration file in server2

We can add the above command in crontab so that two servers in the sync.

Monday, September 29, 2008

MySql ERROR 1054

I was breaking my head when i was doing import data from mysqldump in Linux machine. The problem was "ERROR 1054 (42S22) at line 1564: Unknown column 'cust.CUSTOMER_NAME' in 'field list' ". I surfed the net but i couldn't get any stuff.

Then i put this problem on my guru[Mukund]. He explained the problem.

MySql behave as case-in-sensitive in microsoft environment. So while writing function, procedure and trigger case is no issues in microsoft environment. But in case of Linux, MySql behave as case-sensitive. All the development machines were Microsoft Environment. Production environment is Linux.

To fix this problem [To make Linux case insensitive] add the following line in the file /etc/mysql/my.cnf
lower_case_table_name = 1

This line make MySql case-in-sensitive in linux environment.

Tuesday, September 23, 2008

HTML Redirect to new URL

This is very useful when we want redirect from one page/site to other page/site.
For example the following code written in home.html. Whenever you clicked on this home.html link, browser will take you to

<meta equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta equiv="REFRESH" content="0; URL=">

Here http-equiv="REFRESH" tag reload/redirect the page after the mentioned time in the content tag.
Content=0 means immediately redirect /load the page.

Friday, September 19, 2008

Mysql Error : Mysql has gone away.

I had a problem while import database from my server to local around 117MB size. Suddenly i got in a problem. That was "Mysql has gone away". I surfed the net and got the solution.

When mysql server receives packet more than mentioned in max_allowed_packet in mysql server configuration, mysql server throw out the error "Mysql has gone away".

To fix this problem you can change max_allowed_packet value in my.cnf file in linux machine. This file will be in /etc/mysql/my.cnf

max_allowed_packet = 36M

Restart mysql.

Thursday, September 18, 2008

How to Run Unix shell script in java

I came across the scenario wherein i have to call/ Run the unix shell script. I think this would help you guys.

I have written a script called code:

cp /home/ /home/

In this script just i am copying a file to another.

The java code to call that script.

public class CallScript
public static void main(String s[]) throws Exception{
Runtime rt = Runtime.getRuntime();
try {
String str = "/absolute_path/";
Process child = rt.exec("/bin/bash");
BufferedWriter outCommand = new BufferedWriter(new Output
outCommand.write(str +"\n");

} catch (Exception e) {

Monday, August 25, 2008

Apache load test tool

For web application, to test server load is important one to check the performance.

If you have installed apache in your machine, you could use "ab"[apache benchmarking] command to test the server load.


ab -n 100 -c 100


ab ---> apache command
-n ---> number of requests
-c ---> number of concurrent requests.

for more info

Wednesday, August 20, 2008

How to change default size of terminal [Ubuntu]

You can edit the following file with root access.

The following entry is the one we have to change.

To change the number of columns, change the co# number, in this case 80.
To change the number of rows, change the li# number, in this case 24.
So as an example if you want a terminal window of 80x54:

Now the terminal size would be half of the screen.

Thursday, July 31, 2008

clone hard disk in linux

Install all software for development machine is tedious job. Just think of a team of 5 or above. Linux offer DD command to reduce this job as much as easier.
What we could do with the help of DD command is, just install all the software in one machine and clone that hard disk to other hard disks. Here the constraints is hard disks[source and destination] should be same size.

Step 1:
Install all softwares you want.
Step 2:
Connect the second hard disk to machine where in all software has been installed.
Stop 3:
Mount command list all the media connected in that machine.
Stop 4:
Now you have find out in which hard disk you have already installed all software.
Now two hard disk connected to your machine.
but you can view only one hard disk unless you mount another one. To confirm which media is source and which media is destination, You have to mount.
While run DD command we have to give the name of the media namely sda or sdb etc... So we have to confirm the media name.
To mount
i) Make a directory in /media. For ex /media/hd
ii) run a follwoing command to mount media to a directory.
mount /dev/sda7 /media/hd
/dev directory will contains all media details.
iii) after confirmation of which media is source[for ex sdb] and which media is destination[for ex sda] have to unmount the device using the following command.
umount /media/hd
step 5:
finally you have to run the following command to clone the hard disk from one to another with root user.
dd if=/dev/sdb of=/dev/sda

dd => disk to disk command
if => input file
of => output file

This will take an hour to copy. You could do the same stuff for any number of machines within an hour per machine.
Enjoy maadi.

Tuesday, July 8, 2008

Sort process by memory

The following command help to sort list of process running in linux machine.
ps -eo pmem,pid,args | sort -k 1 -n -r | less

pmem -> list the memory occupied by the process
pid -> process ID
args -> process

Friday, June 20, 2008

database dump for mysql and postgreSQL

User's data is very very important. Obviously most of application stores user data in the database.

Database backup is mandatory those who are use user data in their application.

If something happen to database, using dump we can restore the backup to the database.

MySql database:
To dump/export:
mysqldump --user {username} --password {password} {database} backup.sql

mysqldump is the command to dump/export the database to file.

To undump/import:
mysql --user {username} --password {password} {database}
This will extract backup.sql to the database
PostgreSQL database:

To dump/export:
pg_dump -h {host-name} -U {username} -p {database name} backup.sql

pg_dump is the command to dump the database. The above command dump all data in the database {database} to the backup.sql file.

To undump/import:
psql -h {host-name} -U {username} -p {database name} < backup.sql
Dump/Export postgreSQL database:

Same as mysql this command will import data from backup.sql to the database.

Monday, June 9, 2008

compile lighttpd server from source

To install any server like 'lighttpd' for windows operating system we can download and install using .exe file.
Same way we could do it for other operating system [sun solaris, linux and mac]also. But for some specific distribution there won't be any executable version of software.

In this case, we can compile from source code and install the same.

I explained installation steps in the ubuntu[linux distribution] server.

Login as root.

There is two way to download the source code

1) Using terminal:
Copy the url of the software which we want to install. That might be any kind of compressed format. for ex:[tar.gz,tar.bz2,etc...] and use the following command
wget {URL}
this will downloads source code using terminal.
2) Using GUI
Click on download link and save to local file system.

Steps to compile and install:
i) Uncompress the file which one we downloaded. Using the following command in terminal
if downloaded file is .tar.gz format use tar -xzvf {downloaded file name}
if downloaded file is .tar.bz2 use tar -xjvf {downloaded file name}

ii) Get inside the folder and there is file named "configure" and type the following command
if we want install in any specific directory, mention directory using the following command.
./configure --prefix = {directory}.... [default installation directory is /opt/
The above command will configure the compilation environment.

iii) Type the following to compile
now source code compiled.

iv) To install
make install
Now server is installed and ready for you.

Sunday, May 25, 2008

J2EE vs Ruby

Rails and a typical J2EE Web stack

The Rails stack to a typical J2EE Web stack comprised of the Tomcat servlet container, the Struts Web application framework, and the Hibernate persistence framework.

Comparison of Rails and J2EE stacks

As you can see, the fundamental difference between the Rails stack and the components that make up a common J2EE-based Web application is small. Both have a container in which the application code will execute; an MVC framework that helps to separate the application's model, view, and control; and a mechanism to persist data.Reference

Wednesday, May 7, 2008

Mysql create user, database & access

I broken my head to create user and give access permission to the particular database.

Finally i got the problem that "Version problem".

I am using "mysql Ver 14.7 Distrib 4.1.20, for redhat-linux-gnu (i686)"

If you face this problem then, this post will help you reduce your time.

3) use mysql;
4) update user set select_priv = 'Y',update_priv = 'Y',create_priv = 'Y', delete_priv = 'Y' where user = 'USER_NAME';

Create database.
We haven't created user but granting permission to the user. This will create a user with name {USER_NAME} in the "user" table of "mysql" database.
3) use mysql;
Login to mysql table to update the table level permission.
4) update user set select_priv = 'Y',update_priv = 'Y',create_priv = 'Y', delete_priv = 'Y' where user = 'USER_NAME';
This will update the basic manipulation permission to the user.

Sunday, April 20, 2008

clear session files - Ruby

Session is important for web application as track user. Session grow likely same as log files. This will cause memory overhead. We can clear session using Linux crontab command.

This will remove 300 minutes old session files by every day 00:10 hrs.

Place this command in the crontab file in the /usr/bin/ directroy.

Can edit the crontab file using following command.

crontab -e

* * * * * find absolute_path -name 'sess.*' -amin +300 -exec rm -rf {} \;
10 0 * * * find /home/tmp -name 'ruby_sess.*' -amin +300 -exec rm -rf {} \;

find - find the file that start with the name sess.

min +300
- find the session file with 300 minutes old

exec rm -rf - execute the command remove the files which is 300 minutes old.

Wednesday, April 16, 2008

Rotate log files

Logging is come into picture when something went wrong in application and have to point out the root cause of the problem.

Some times application running out of disk space. This is not because of our code but because of log files generated by apps.

Logrotate is effective utility for manage files which grow rapidliy like catalina.out and etc....

To rotate ghe old log files we can use log4j in java ,log4r in Ruby. There is another cool way to Rotate the log in unix based servers.

There is a configuration file called logrotate.conf in /etc directory. Add the following code

# Rotate MyApps logs
1) /home/MyApps/log/*.log {
3) missingok
4)rotate 5
9)create 0666 devgroup devgroup

This will take care of log file to rotate.

1) /home/MyApps/log/*.log {
Absolute path to log file of project
rotate log files daily
3) missingok
If log file is missing dont raise any error.
4)rotate 5
Log files rotated <5> times
for Example the directory /log look like:
Old rotated file compressed to by default gzip
postpone compression of previous log file to next rotate
current log would be production.log and previous log would be
production.log.1 not production.log.1.gz
for Example the directory /log look like:
don't rotate if log file is empty
Truncate the original log file in place after creating a copy, instead of moving the old log file and optionally creating a new one.
9)create 0666 devgroup devgroup
The file permission, user and group name of the rotated files
file permission====> 0666
username =====> devgroup
groupname =====> devgroup

Go and start play with logrotate.

Monday, April 7, 2008

Database backup script

The script to take a backup of postgres database

Step i)
Write a shell script to dump the database.
Create a .sh file using vi editor inside the /bin as follows...
vi /bin/

1) #!/bin/bash
2) BACKUP_DIR="/home/MyApps/regular_backup"
3) PGHOST=""
4) PGUSER="postgres"
5) /usr/bin/pg_dumpall -h $PGHOST -U $PGUSER | gzip > $BACKUP_DIR/backup.gz

The first line #!/bin/bash is just a declaration that this is a BASH script.

2) BACKUP_DIR="/home/MyApps/regular_backup"
This line tells the target folder where our .gz file to be stored

3) PGHOST=""
4) PGUSER="postgres"
Host IP where our postgres database is running and user name. If some other database have to add password .

5) /usr/bin/pg_dump -h $PGHOST -U $PGUSER | gzip > $BACKUP_DIR/backup.gz
This key statement is dump the database using command[/usr/bin/pg_dumpall] and user name and password[-h $PGHOST -U $PGUSER] and zip it up using gzip and target file backup.gz

after saved this file should the file permission to 755
chmod 755 /bin/

Step ii) Add this script to crontab [Crontab (CRON TABle)is a program that manipulates the CRON daemon] and configure time to run script.

1) Edit crontab file in the directory /usr/bin/crontab file using crontab -e -e for edit/add entry in the crontab file.

2) Add this line in crontab file
10 0 * * * /bin/ >/dev/null 2>&1

This crontab run the script /bin/ on the time frame.

10 0 * * * is 10 minute 0 hours of every day every month end every year run the script which we have created in step 1[/bin/]

Your script is ready and will run and backup the database everyday morning 00:10

Sunday, April 6, 2008

Online Video download

One of the place to surf online English films

Sunday, March 23, 2008


The term CAPTCHA (for Completely Automated Turing Test To Tell Computers and Humans Apart) was coined in 2000 by Luis von Ahn, Manuel Blum, Nicholas Hopper and John Langford of Carnegie Mellon University. At the time, they developed the first CAPTCHA to be used by Yahoo.