satishgaudo.com

Understanding technology

Linux commands

sed -i ’s/abc/xyz/g’ *.php
This command is used for mass replacemet using regular expression.
In the above command “abc” is replace with “xyz” from all the files extension “php”.

find /var/www/html/sch_admin/ -mtime -1

This command is used to list all the files within the specified folder,say “var/www/html/sch_admin/”, which have been created or modified within the period specified,say “-1″ which is last one day.

tar xvzf pig-0.5.0.tar.gz
untar the tar.gz file

Add /pig-n.n.n/bin to your path. Use export (bash,sh,ksh) or setenv (tcsh,csh). For example:
export PATH=/root/pig-0.5.0/bin:$PATH

Set JAVA_HOME as follows using syntax export JAVA_HOME= .
If your path is set to /usr/java/jdk1.5.0_07/bin/java, set it as follows:
export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/jre

Tip: Use the following command to find out exact path to which java executable under UNIX / Linux:
$ which java

* export command is used to set environment variable relevant on during the current session

For permanent setup – edit .bash_profile – as it get all the vars set on login

vi ~/.bash_profile
export JAVA_HOME=/usr
export PATH=/root/pig-0.5.0/bin:$PATH

Bookmark and Share
30 January 2010 at 12:22 - Comments

Export the query result in a temporary file

select video_file from videos INTO OUTFILE ‘/tmp/video1.txt’;

Query Above exports all the rows for coulmn video_file into a text file “/tmp/video1.txt” .

Bookmark and Share
20 January 2010 at 14:16 - Comments

100-year old building collapses at dockyard road – Mumbai,India

The evacuation of the 75 families who used to stay in the building was done in time otherwise there would have been many casualties. The five storied Reay building opposite the Dockyard railway station in Mumbai was more than 100 years old and notice had already been given for its evacuation. Residents picking their belongings from the debris

Bookmark and Share
13 January 2010 at 17:33 - Comments

HTTP: Persistent connections

In HTTP/0.9 and 1.0, the connection is closed after a single request/response pair. In HTTP/1.1 a keep-alive-mechanism was introduced, where a connection could be reused for more than one request.

Such persistent connections reduce lag perceptibly, because the client does not need to re-negotiate the TCP connection after the first request has been sent.

Version 1.1 of the protocol made bandwidth optimization improvements to HTTP/1.0. For example, HTTP/1.1 introduced chunked transfer encoding to allow content on persistent connections to be streamed, rather than buffered. HTTP pipelining further reduces lag time, allowing clients to send multiple requests before a previous response has been received to the first one. Another improvement to the protocol was byte serving, which is when a server transmits just the portion of a resource explicitly requested by a client.

Reference URL: http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol

Bookmark and Share
8 January 2010 at 16:38 - Comments

shell script to back up database and script folders

#!/bin/bash
cd /ct20/uploads/backup/
NOW=$(date +”%m-%d-%Y”)
tar -cjf backupsite_$NOW.bz2 /opt/www/ct20
tar -cjf backupcms_$NOW.bz2 /opt/www/cms
tar -cjf mysqlbackup_$NOW.bz2 /opt/lib/mysql

Bookmark and Share
27 October 2009 at 12:00 - Comments

shell script to optimize database

DB_LIST=”$(mysql -u root -Bse ’show databases’ | egrep -v ‘information_schema|mysql|test’)”
for db in ${DB_LIST[@]}
do
TABLENAMES=”$(mysql -u root $db -Bse ’show tables’)”
echo “Database: “$db
for TABLENAME in ${TABLENAMES[@]}
do
mysql -u root $db -Bse “optimize TABLE $TABLENAME;”
echo $TABLENAME” table has been optimized”
done
echo $db – $TABLENAME “Optimized has been completed”
done
echo “All Databases have been successfully Optimized”

Bookmark and Share
27 October 2009 at 11:57 - Comments

shell script to Analyze database

DB_LIST=”$(mysql -u root -Bse ’show databases’ | egrep -v ‘information_schema|mysql|test’)”
for db in ${DB_LIST[@]}
do
TABLENAMES=”$(mysql -u root $db -Bse ’show tables’)”
echo “Database: “$db
for TABLENAME in ${TABLENAMES[@]}
do
mysql -u root $db -Bse “Analyze TABLE $TABLENAME;”
echo $TABLENAME “Analyze has been done”
done
echo $db – $TABLENAME “Analyzis has been completed”
done
echo “All Databases have been successfully Optimized”

Bookmark and Share
27 October 2009 at 11:56 - Comments

glob — Find pathnames matching a pattern

$aDir = glob(”/clt20/uploads/videos/*.flv”);

The glob() function searches for all the pathnames matching pattern according to the rules used by the libc glob() function, which is similar to the rules used by common shells.

Bookmark and Share
27 October 2009 at 11:54 - Comments

shell script to rotate logs between remote servers

cd /var/log/httpd
NOW=$(date +”%m-%d-%Y”)
mv mobile-error_log mobile-error_log-$NOW
mv mobile-access_log mobile-access_log-$NOW
/etc/init.d/httpd graceful
sleep 5
tar -cvjf /opt/logbackup/logs-$NOW.bz2 mobile-error_log-$NOW mobile-access_log-$NOW
scp mobile-access_log-$NOW domU-12-31-39-07-75-63:/clt20/uploads/mobilelog/
rm -f mobile-error_log-$NOW mobile-access_log-$NOW

Remember we have exchanged the authentication key between the two servers.

Bookmark and Share
27 October 2009 at 11:47 - Comments

Linux rsync command

Following command is used for remote syncing of a folder on two remote servers:

/usr/local/bin/rsync -avz -e ssh /opt/www/cms/imagedata/2009/oct/ webdoc@domU-12-31-39-03-09-20:/opt/www/clt20/imagedata/2009/oct/

To rsync a particular file use:

/usr/local/bin/rsync -avz -e ssh /opt/www/clt20/rss.xml webdoc@domU-12-31-39-03-09-20:/opt/www/clt20/

Bookmark and Share
21 October 2009 at 19:41 - Comments