Search This Blog

Tuesday, December 28, 2010

Linux Shell Command to Findout PV's from Apache Access Log

cat /var/log/httpd/access.log | cut -d'"' -f2 | cut -d' ' -f2 | cut -d'.' -f2 | cut -d'?' -f1 | cut -d'/' -f1 | grep -v -P "gif|jpg|ico|png" | wc -l

Friday, December 10, 2010

How to add additional ip into linux - ubuntu

modify /etc/network/interfaces

add the following


auto eth0:0
iface eth0:0 inet static
address xx.xx.xx.xx
gateway xx.xx.xx.xx
netmask xx.xx.xx.xx
network xx.xx.xx.xx
broadcast xx.xx.xx.xx

example,
auto eth0:0
iface eth0:0 inet static
address 192.168.0.100
gateway 192.168.0.1
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255

AND, finally restart networking service

/etc/init.d/networking restart

Wednesday, December 8, 2010

Tuesday, December 7, 2010

Example of singleton class in PHP

<?
class singleton
{
    private static $_instance;

    public static function getInstance()
    {
        if (!(self::$_instance instanceof self))
        {
            self::$_instance = new self();
        }

        return self::$_instance;
    }

    // Do not allow an explicit call of the constructor: $v = new Singleton();
    final private function __construct() { }

    // Do not allow the clone operation: $x = clone $v;
    final private function __clone() { }
}

$instance = singleton::getInstance();
?>

Setting up an email notification for subversion repository

Add the following piece of code in the /.../<<svnroot>>/<<repository_name>>/hooks/post-commit


#!/bin/sh
REPOS="$1"
REV="$2"
/usr/local/bin/svnnotify -r "$REV" -C -d -H Alternative \
 --alt HTML::ColorDiff -p "$REPOS" -t "xxxx@xxxx.com" \
 --from 'SVN @ xxxx.com <svn@xxxx.com>'

if svnnotify command is not present on your svn server then use following code in the post-commit file

#!/bin/sh
REPOS="$1"
REV="$2"
/usr/bin/svnlook diff -r "$REV" "$REPOS" | mutt -s "SVN Notify" xxxx@xxxx.com

Thursday, December 2, 2010

Mysql Replication - From one database on master to another database on slave

Mysql Replication - From one database on master to another database on slave


Tells the slave to translate the default database (that is, the one selected by USE) to to_name if it wasfrom_name on the master. Only statements involving tables are affected (not statements such as CREATE DATABASEDROP DATABASE, and ALTER DATABASE), and only if from_name is the default database on the master. This does not work for cross-database updates. To specify multiple rewrites, use this option multiple times. The server uses the first one with a from_name value that matches. The database name translation is done before the --replicate-* rules are tested.
If you use this option on the command line and the “>” character is special to your command interpreter, quote the option value. For example:
shell> mysqld --replicate-rewrite-db="olddb->newdb"

TO READ THE ORIGINAL ARTICLE AT dev.mysql.com, Click Here

Table Cache - Mysql Server - Performance Tunning

One of the many important parameter is table cache

__ Tables ______________________________________________________________
Open              533 of 2048    %Cache:  26.03
Opened          2.18k     0.0/s

(1) If the %Cache is inching towards 100% mark then it is good time to increase table cache value in my.cnf

table_cache = 2048

(2) Rate of opening table is another way to judge if the value of table cache needs any change. Rate of 1/s or Lower is a GOOD indicator. Anything above means - table cache needs to be increased.

Wednesday, December 1, 2010

shell script to send email alert - if mysql replication is down

#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

mysql_hostname="-h localhost"
mysql_username="-u root"
mysql_userpass="" #-p pass
email_to="xxxx@xxxx.com"
email_subject="Replication is Down"
tmp_replication_slave_reason_filepath="/tmp/replication_slave_reason.txt"

if [ -f $tmp_replication_slave_reason_filepath ]; then
        rm -rf $tmp_replication_slave_reason_filepath
fi

echo "show slave status\G;" |mysql $mysql_username $mysql_hostname $mysql_userpass 2>&1 |grep "Slave_IO_Running: No"
if [ "$?" -ne "1" ]; then
        echo "Slave_IO_Running: No" >> $tmp_replication_slave_reason_filepath
fi

echo "show slave status\G;" |mysql $mysql_username $mysql_hostname $mysql_userpass 2>&1 |grep "Slave_SQL_Running: No"
if [ "$?" -ne "1" ]; then
        echo "Slave_SQL_Running: No" >> $tmp_replication_slave_reason_filepath
fi

if [ -f $tmp_replication_slave_reason_filepath ]; then
        mail -s $email_subject $email_to < $tmp_replication_slave_reason_filepath
        echo $tmp_replication_slave_reason_filepath
fi