IT notes

aax2m4b

Convert an audiobook .aax to .m4b using ffmpeg brew install chromedriver ffmpeg sudo easy_install pip pip install selenium requests git clone https://github.com/inAudible-NG/audible-activator cd audible-activator sed -i '' 's,chromedriver_path = "./chromedriver",chromedriver_path = "/usr/local/bin/chromedriver",' audible-activator.py ./audible-activator.py When running audible-activator.py It will ask for the audible username/password it will open chrome, and when finish print the activation bytes: $ ./audible-activator.py Username: [email protected] Password: [*] Player ID is 1xmjyl5rSw0yVb/olWBYuU/NBxk= activation_bytes: b97f4709 One having the activation_bytes, use ffmpeg:

tmux ssh

Tmux multiple ssh connections with synchronized panels If need to debug/check in real-time multiple servers via ssh, this can be used. tmux script #!/bin/sh TARGET="tmux-ssh" SSH_USER="devops" i=0 while read line do if [ $i == 0 ] then tmux new-window -a -n ${TARGET} "ssh -l ${SSH_USER} ${line}" else tmux split-window -t "${TARGET}" "ssh -l ${SSH_USER} ${line}" && \ tmux select-layout -t "${TARGET}" tiled fi let i++ done < "${1:-/dev/stdin}" tmux set-window-option -t ${TARGET} synchronize-panes on hosts If the input is json, jq can be used to extract hosts, assuming your output is similar to:

beanstalkd

Beanstalkd Beanstalkd is a big to-do list for your distributed application. If there is a unit of work that you want to defer to later (say, sending an email, pushing some data to a slow external service, pulling data from a slow external service, generating high-quality image thumbnails) you put a description of that work, a “job”, into beanstalkd. Some processes (such as web request handlers), “producers”, put jobs into the queue.

mysql db size

How big is your data: SELECT IFNULL(B.engine,'Total') "Storage Engine", CONCAT(LPAD(REPLACE(FORMAT(B.DSize/POWER(1024,pw),3),',',''),17,' '),' ', SUBSTR(' KMGTP',pw+1,1),'B') "Data Size", CONCAT(LPAD(REPLACE( FORMAT(B.ISize/POWER(1024,pw),3),',',''),17,' '),' ', SUBSTR(' KMGTP',pw+1,1),'B') "Index Size", CONCAT(LPAD(REPLACE( FORMAT(B.TSize/POWER(1024,pw),3),',',''),17,' '),' ', SUBSTR(' KMGTP',pw+1,1),'B') "Table Size" FROM (SELECT engine,SUM(data_length) DSize,SUM(index_length) ISize, SUM(data_length+index_length) TSize FROM information_schema.tables WHERE table_schema NOT IN ('mysql','information_schema','performance_schema') AND engine IS NOT NULL GROUP BY engine WITH ROLLUP) B, (SELECT 3 pw) A ORDER BY TSize; This will print something like:

raw2vmdk

Convert raw image to vmdk Install qemu: $ brew install qemu Convert using: $ qemu-img convert -f raw -O vmdk disk.raw disk.vmdk

brew update formula

First do a fork of the repo: https://github.com/Homebrew/homebrew-core Go to the homebrew/core repository: $ cd $(brew --repository homebrew/core) Add your fork as a remote: $ git remote add <youruser> [email protected]:<youruser>/homebrew-core.git Git change to your branch and do changes: $ git checkout -b your-project Test the formula (example for immortal): $ brew uninstall --force immortal $ brew install --build-from-source immortal $ brew audit --strict immortal Submit changes and squash commits:

bastion ssh

Bastion usin ssh multiplexing Replace your.bastion.tld with your bastion server and set your bastion username in the ProxyCommand: Host bastion Hostname your.bastion.tld ForwardAgent yes ControlPath ~/.ssh/cm-%r@%h:%p ControlMaster auto ControlPersist 10m Host 10.10.* ProxyCommand ssh <your-username>@bastion -W %h:%p example To login with user devops to server 10.10.3.4: $ ssh -l devops 10.10.3.4 or $ ssh [email protected]

smarthost

Smarthost with postfix A smart host is a type of email message transfer agent that allows a Simple Mail Transfer Protocol (SMTP) server to route email to an intermediate mailserver rather than directly to the recipient’s server https://en.wikipedia.org/wiki/Smart_host Setup postfix to forward all emails using an external SMTP server, for example sendgrid.net, main.cf: smtp_sasl_auth_enable = yes smtp_sasl_password_maps = static:username:password smtp_sasl_security_options = noanonymous smtp_tls_security_level = encrypt header_size_limit = 4096000 relayhost = [smtp.

mtr

mtr to create a text file report $ sudo mtr --report --report-cycles 10 immortal.run > /tmp/immortal-mtr.txt Example of output: Start: Tue Apr 25 17:58:11 2017 HOST: M20160001.local Loss% Snt Last Avg Best Wrst StDev 1.|-- 10.19.15.254 0.0% 10 41.7 41.2 25.1 81.6 16.8 2.|-- 10.19.0.1 0.0% 10 0.5 0.5 0.4 0.6 0.0 3.|-- 23.189.27.97 0.0% 10 1.2 8.5 1.0 74.4 23.2 4.|-- 89.27.149.117 80.0% 10 1.3 18.4 1.3 35.

mysql backup

mysqldump + xz + openssl First add to .my.cnf the proper username/password to avoid getting a warning: [client] host = localhost user = dbadmin password = secret To take the dump and keep it only for 31 days: #!/bin/sh DAY=$(date +%d) mysqldump --events --routines --triggers --add-drop-database --compress --hex-blob --opt --skip-comments --single-transaction dbname | \ xz -c | \ openssl smime -encrypt -aes256 -binary -out /safe/path/${DAY}.sql.xz.enc -outform DER /path/to/cert.pem mysqldump The options used: