IT notes

mysql pager

To use less command to vie the output of a mysql result you could use: mysql> \P less or mysql> pager less Then run something like: mysql> show engine innodb status\G In some cases you may need to search for something in specific for this grep could be used, for example: mysql> \P grep -A7 "ROW OPERATIONS" PAGER set to 'grep -A7 "ROW OPERATIONS"' Then when running the command it will only return 7 lines after “ROW OPERATIONS”

//+build disable

In go if need to sketch something and end having func main() in two files, you could ignore building one by adding at the top of the file: // +build disable This is a build constraint. A build constraint, also known as a build tag, is a line comment that begins: // +build

delete file

Ways to delete a file starting with a dash / hyphen: rm -- -file The option -- means the end of options for the command. Another option is to indicate where is the file: rm ./-file . is current directory , path to -file is ./-file Using find: find . -type f -exec rm {} \; Finding the inode: ls -li Then using find and the inode it can be removed with:

galera SOS

Check status of cluster: Find process list not sleeping: SELECT user, time, state, info FROM information_schema.processlist WHERE command != 'Sleep' AND time >= 2 ORDER BY time DESC, id; Get locked tables: show open tables where in_use > 0; Finding locks: show engine innodb status; At the end: ---TRANSACTION 1135701157, ACTIVE 6768 sec MySQL thread id 5208136, OS thread handle 0x7f2982e91700, query id 882213399 xxxIPxxx my_user cleaning up kill the transaction thread:


To compress using gzip format but using all your available cores: tar --use-compress-program=pigz -cf archive.tgz /path/to/source Or if you want to pipe it: tar -cf - source | pigz > archive.tgz To decompress use tar -xvf archive.tgz as usual. The output of pigz is compatible with gzip


Edit environment variables: vared PATH Diff command output creating temporary normal files vimdiff =(ls /bin) =(ls /usr/bin) Print path print -l $path Run a command detached &! or &| put it in background and disown the process, exiting the shell will leave it running: sleep 300 &!

Google Cloud Functions

Testing Google Cloud Functions using go with an average of 250 requests/second. Cost per day close to $10USD Request per day: 23,511,849 Errors: 0 memory usage: 10.4MB execution time: 55.04ms

ssh wireshark

To analyze traffic remotely over ssh: ssh [email protected] sudo tcpdump -U -s0 -i pflog0 -w -| wireshark -k -i - In case need an specific port: ssh [email protected] sudo tcpdump -U -s0 -i pflog0 -w - 'port 5984' | wireshark -k -i - To ignore trafic from ssh: ssh [email protected] sudo tcpdump -U -s0 -i pflog0 -w - 'not port 22' | wireshark -k -i -

ELK delete_by_query

To delete indexes older than X days: POST haproxy/_delete_by_query { "query": { "range": { "ISODATE": { "lt": "now-3d" } } } }

openssl SHA1 HMAC

To create an HMAC-SHA1: $ echo -n "string" | openssl sha1 -hmac "shared_secret" or $ echo -n "string" | openssl dgst -sha1 -hmac "shared_secret"