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

auto eth0:0
iface eth0:0 inet static

AND, finally restart networking service

/etc/init.d/networking restart

Thursday, December 9, 2010

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

/usr/local/bin/svnnotify -r "$REV" -C -d -H Alternative \
 --alt HTML::ColorDiff -p "$REPOS" -t "" \
 --from 'SVN @ <>'

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

/usr/bin/svnlook diff -r "$REV" "$REPOS" | mutt -s "SVN Notify"

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"


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


mysql_hostname="-h localhost"
mysql_username="-u root"
mysql_userpass="" #-p pass
email_subject="Replication is Down"

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

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

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

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

Wednesday, November 24, 2010

Command to monitor mysql replication slave status

watch 'mysql -u xxxx -p xxxx -e "show slave status\G" | grep "Last_"'

Mysql processlist monitoring

To check running queries

watch 'mysqladmin -u xxxx -p xxxx processlist | grep -v Locked | grep -v Sleep | grep -v Waiting'

To check Locked queries + count for each query

watch 'mysqladmin -u xxxx -p xxxx processlist | grep Locked | cut -d"|" -f9 | sort | uniq -c'

Change next AUTO_INCREMENT value in mysql table

The command to change next AUTO_INCREMENT value in mysql table is


Common myisamchk options

myisamchk -mfq xxxx.MYI

  -m, --medium-check  Faster than extend-check, but only finds 99.99% of
                      all errors.  Should be good enough for most cases.

  -f, --force         Restart with '-r' if there are any errors in the table.
                      States will be updated as with '--update-state'.

  -q, --quick         Faster repair by not modifying the data file.
                      One can give a second '-q' to force myisamchk to
                      modify the original datafile in case of duplicate keys.
                      NOTE: Tables where the data file is currupted can't be
                      fixed with this option.

Getting the data Sync'ed between master & slave servers in mysql replication

In order to get the database.tables sync'ed between master and slave server, follow these guidelines

  1. Shutdown mysql daemon on master server
  2. Shutdown mysql daemon on slave server
  3. Take dump of database.tables on master server
  4. Take backup of database.tables on slave server
  5. Load dump (of master) on slave
  6. Start mysql daemon on master server
  7. Take a note of new binlog filename on master server
  8. Update the master binlog filename on slave server
  9. Start mysql daemon on slave server

Find broken symlinks in linux

In order to find broken links in linux, we will use find command with some shell scripting

for i in `find ./ -type l`; do [ -e $i ] || echo $i; done