Saturday, 28 January 2012

mysqlhotcopy vs mysqldump

mysqlhotcopy is a Perl script that was originally written and contributed by Tim Bunce. It uses LOCK TABLES, FLUSH TABLES, and cp or scp to make a database backup quickly. It is the fastest way to make a backup of the database or single tables, but it can be run only on the same machine where the database directories are located. mysqlhotcopy works only for backing up MyISAM and ARCHIVE tables. It runs on Unix and NetWare

 The mysqldump client is a backup program originally written by Igor Romanenko. It can be used to dump a database or a collection of databases for backup or transfer to another SQL server (not necessarily a MySQL server). The dump typically contains SQL statements to create the table, populate it, or both.

 If you are doing a backup on the server and your tables all are MyISAM tables, consider using the mysqlhotcopy instead because it can accomplish faster backups and faster restores.

InnoDB vs MyISAM

MyISAM and InnoDB are the two most-common database engines available.  While installing the DB most of them don't even take the time to select a storage-engine and just accept the database default. 

The storage-engine is what which store, handle, and retrieve information for a particular table.

1. MyISAM

 It is the default engine with MySQL. Data in MyISAM tables is split between three different files on the disk.One for the table format, another for the data, and lastly a third for the indexes. 

2. InnoDB

 InnoDB is transaction-safe means data-integrity is maintained throughout the entire query process. InnoDB also provides row-locking, as opposed to table-locking, means when one query is busy updating or inserting a row, another query can update a different row at the same time.

InnoDB boasts is the ability to use foreign-key constraints. FK constraints allows developers to ensure that inserted data referencing another table remains valid.
MyISAM v/s InnoDB

   MyISAM in most cases will be faster than InnoDB. It is the default engine chosen by the MySQL development team. 

In  InnoDB features like row-level locking, transaction-safe queries, and relational table design are all very fast.

InnoDB recovers from a crash or other unexpected shutdown by replaying its logs. MyISAM must fully scan and repair or rebuild any indexes or possibly tables which had been updated but not fully flushed to disk.

Friday, 27 January 2012

How to install java Runtime environment in linux

Get the latest version of java from the following link
http://www.oracle.com/technetwork/java/javase/downloads/index.html

I  got a jdk-6u7-linux-i586.bin for linux

# mkdir -p /usr/java

# cd /usr/java

# chmod 700 /tmp/jdk-6u7-linux-i586.bin 

# /tmp/jdk-6u7-linux-i586.bin ---- tmp is the location where i download the package 

# export JAVA_HOME=/usr/java/jdk1.6.0_10 
# export PATH=$JAVA_HOME/bin:$PATH 
# which java
/usr/java/jdk1.6.0_10/bin/java
# java -version
 
    

How to Install Tomcat in linux


Get the package first


To run Tomcat, you need Java Standard Edition (Java SE), also known as the JDK

Then follow the steps below

# groupadd tomcat

# useradd -g tomcat -s /sbin/nologin -m -d /home/tomcat tomcat 

# md5sum /opt/src/apache-tomcat-6.0.29.tar.gz 

# cd /opt/src/ 

# tar -xzvf apache-tomcat-6.0.29.tar.gz 

# mv apache-tomcat-6.0.29  /usr/local/src/ 

# cd /usr/local/src/apache-tomcat-6.0.29/

# chown -R tomcat.tomcat apache-tomcat-6.0.29/ 

# cd apache-tomcat-6.0.29/ 

# cd bin/ 

# ./version.sh 

# export CATALINA_HOME=/usr/local/src/apache-tomcat-6.0.29
# export CATALINA_BASE=/usr/local/src/apache-tomcat-6.0.29

# su - tomcat -s /bin/sh -c /usr/local/src/apache-tomcat-6.0.29/bin/startup.sh

# top -u tomcat 

# su - tomcat -s /bin/sh -c /usr/local/src/apache-tomcat-6.0.29/bin/shutdown.sh

# top -u tomcat

# cd bin 

# ./catalina.sh run or sh startup.sh or ./startup.sh

To switch as tomcat user
# su - tomcat -s /bin/sh
# su - tomcat -s /bin/bas


if not switching as tomcatuser use the following to run a command
# su - tomcat -s /bin/sh -c path/of/the/command/to/run

change ports of tomcat
# vim conf/server.xml

Tomcat logs
# cd logs/catalina.ou

Thursday, 26 January 2012

command line arguments

This is just to demonstrate the command line arguments in a shell script

#!/bin/bash

# Script that demonstrate, command line arguments

echo "Total number of command line argument are: $#"

echo "script name is: $0"

echo "$1 is first argument"

echo "$2 is second argument"

echo "All of them are :- $* or $@"

# sh filename.sh 1 2 3 4 5 (arguments)

$* - This denotes all the parameters passed to the script at the time of its execution

$@ - denotes all the parameters passed to the script at the time of its execution

$0 - Name of the shell script being executed

$$ - Pid of current process

$# - Number of arguments specified in the command line

$? - Exit status of the last command

To see the process Id of the current shell
# echo $$ 
 
Exit status of a command 
# echo $?

The above symbols are known as positional parameters.

Download files using shell

This is just a basic for the beginners

#!/bin/bash
echo -en "\e[31mEnter link To Download:\e[0m "  

# echo -en "\e[31;1mEnter link:\e[0m "  
# -n so that the value can be entered in the same line itself.

read lnk

#echo -e "\e[0m"
# read command reads the value from standard input.

cd /root/downloads && wget $lnk

# 31 - Red
# 32 - Green
# 34 - Blue

# 31;1m - Bold Red
# 31;7m - Invert Red to background.

Make shell script interactive using ' read '

We can make the shell script interactive. read will let the user to enter values while the script is being executed. Input entered through the keyboard read into the variables followedby read, and the program execution continues.


Download Songs


Download Full songs from a site one by one according to the film name

#!/bin/bash

URL="http://sensongs.com"

lynx -dump $URL | grep -o "http:.*" | grep -E "HindiSongs.htm|MalayalamSongs.htm|TamilSongs.htm" |sort -u > link

for i in `cat link`
do
IURL="$i"
NAME=`echo ${i:20} | cut -d. -f1`

if [ -d ~/Music ]; then
cd ~/Music
else
mkdir -p ~/Music
cd ~/Music
fi

if [ -d ~/Music/sensongs.com ]; then
cd ~/Music/sensongs.com
else
mkdir  ~/Music/sensongs.com
cd ~/Music/sensongs.com
fi

if [ -d "$NAME" ]; then
cd $NAME
else
mkdir $NAME
cd $NAME
fi

lynx -dump $IURL | grep -o "http:.*" | grep -vE "TamilSongs|NFls|Home|Telugu|Hindi|Pakistani|Malayalam|Kannada|OtherSongs|ContactUs" > songs.txt

for j in `cat songs.txt`
do
MP3=`echo ${j:20} | cut -d. -f1`

if [ -d "$MP3" ]; then
cd $MP3
else
mkdir $MP3
cd $MP3
fi

lynx -dump $j|grep -o "http:.*"|grep ".mp3$|.wma$" |xargs wget -c
cd ..
 done
   done