Skip to content

Instantly share code, notes, and snippets.

@urbels
urbels / mysql_optimizer
Created July 17, 2013 08:02
Table optimize
#!/bin/sh
echo -n "MySQL username: " ; read username
echo -n "MySQL password: " ; stty -echo ; read password ; stty echo ; echo
mysql -u $username -p"$password" -NBe "SHOW DATABASES;" | grep -v 'lost+found' | while read database ; do
mysql -u $username -p"$password" -NBe "SHOW TABLE STATUS;" $database | while read name engine version rowformat rows avgrowlength datalength maxdatalength indexlength datafree autoincrement createtime updatetime checktime collation checksum createoptions comment ; do
if [ "$datafree" -gt 0 ] ; then
fragmentation=$(($datafree * 100 / $datalength))
echo "$database.$name is $fragmentation% fragmented."
mysql -u "$username" -p"$password" -NBe "OPTIMIZE TABLE $name;" "$database"
@urbels
urbels / Apache-to-Nginx-hosts.sh
Created July 17, 2013 09:00
thx to slowpoke Slowpoke
#!/bin/bash
# Apache virtual hosts => Nginx Virtual Hosts
# Usage: ./apache-to-nginx-hosts.sh /etc/apache2/sites-available/www.slowb.ro > /etc/nginx/sites-available/www.slowb.ro
# Author: Slowpoke
# Website: www.slowb.ro
# Download script: http://sprunge.us/AdXH or http://pastebin.com/RbTqBnsm
# Global Vars
port=8080
pattern=".*#.*"
@urbels
urbels / cloudbot
Created September 18, 2013 07:54 — forked from frdmn/cloudbot
SysVinit start up daemon for CloudBot --- touch /etc/init.d/cloudbot && chmod 700 /etc/init.d/cloudbot && pico /etc/init.d/cloudbot
#!/bin/sh
### BEGIN INIT INFO
# Provides: cloudbot
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: SysVinit start up daemon for CloudBot
# Description: Start up daemon for CloudBot
@urbels
urbels / mysql dump
Created October 18, 2013 11:51
mysql dump + free space check + remove oldest to free up space
#!/bin/sh
user=user
ftpuser=$user
pass=password
db=dbname
host=remote/local
BkUp_dir="/home/$ftpuser/dbdump/"
########################################
@urbels
urbels / migratesql.txt
Created December 4, 2013 09:42
migrate mysql from one server to another with ssh
mysqldump -u root -pPASSWORD. --all-databases | ssh user@newhost.com 'cat - | mysql -u root -pPASSWORD'
after this run flush privileges;
@urbels
urbels / gist:9545586
Created March 14, 2014 10:49
Regular expression cheat sheet for Varnish
Regular expression cheat sheet for Varnish
Varnish regular expressions are NOT case sensitive. Varnish uses POSIX
regular expressions, for a complete guide, see: "man 7 regex"
Basic matching:
req.url ~ "searchterm"
True if req.url contains "searchterm" anywhere.
req.url == "searchterm"
#!/bin/bash
CURRENT=$(/usr/bin/quota | awk '{print $2,$3}' | awk 'NR==3{print}' | awk '{print $1}')
MAX=$(/usr/bin/quota | awk '{print $2,$3}' | awk 'NR==3{print}' | awk '{print $2}')
x=$CURRENT
y=$MAX
z=$((x*100/y))
THRESHOLD=60
if [ "$z" -gt "$THRESHOLD" ] ; then