How quickly to check time of mysql query by running it N times

After query optimization I just needed to run query several times to check time and compare it with original query. Query code was placed into query.sql file.

TIMEFORMAT=%R && for i in {1..10}; do time mysql < query.sql > /dev/null; done

Continue reading

Oneliner to check InnoDB status in MySQL every second

Oneliner to check InnoDB status in MySQL every second:

while sleep 1; do date >> /tmp/mysql_innodb_status_log && mysql -e "show engine innodb status\G;" >> /tmp/mysql_innodb_status_log; done

Simulate cron environment

Sometimes scripts aren’t working in cron, but they’re working manually. To debug them it’s helpful to simulate their running under cron environment.

add this to cron and let it to run at least once

* * * * * env > ~/cron_env

run this command to simulate environment:

env - `cat ~/cron_env` /bin/sh

Don’t run script if it’s running

The script will start only in case if the same script is not running.

#!/bin/bash
if ps -ef | grep -v grep | grep "process name" ; then
    echo "process running"
    exit 0
else
    echo "process not running"
    exit 0
fi

Download git with key-based access

This is how to download git project with key-based access:

ssh-agent bash -c 'ssh-add <key file>; git clone git@bitbucket.org:<user>/<repo name>.git'

Enable 80 port in CentOS

If you did an Apache installation then you also need to enable 80 port in iptables:

iptables -I INPUT 5 -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT