IT notes

Prevent Mac to Sleep

To stop sleep entirely: sudo pmset -a disablesleep 1 To revert, allow sleep again: sudo pmset -a disablesleep 0 To display global power settings: pmset -g

sudo SSH_CONNECTION

When using ssh, if then doing something like sudo -i the environment vars are gone, to preserve modify your sudoers (/usr/local/etc/sudoers or /usr/local/etc/sudoers.d/devops) and add something like: Defaults env_keep += "SSH_TTY SSH_CONNECTION SSH_CLIENT" In this case, it will preserve your SSH environment vars.

vbox headless

To list your vms: $ VBoxManage list vms To run one in headless mode: $ VBoxManage startvm freebsd-server --type headless To shutdown: $ VBoxManage controlvm freebsd-server acpipowerbutton To get the IPv4: $ VBoxManage guestproperty enumerate freebsd-server | awk '/IP/' for this to work you will need the vboxguest tools pkg install virtualbox-ose-additions

ddcctl

To share one monitor, keyboard and mouse between two devices, mac mini and a macbook try: brew cask install barrier Then to avoid changing the input source by using the buttons in the monitor try https://github.com/kfix/ddcctl: cd /tmp git clone https://github.com/kfix/ddcctl.git cd ddcctl make && make install In my case to switch from the mac mini (HDMI) to the laptop via (DP) I use: ddcctl -d 1 -i 15 From the laptop (USB-C -> DP) to HDMI, switch back to the mac mini:

timestamp

To get the current unix timestamp: date +%s To get the date from a timestamp: date -r 1559591041 In Linux: date -d "@1559591041"

docker prune

Docker cleanup:  docker system prune -a

rust docker

Dockerfile to create small rust docker images: FROM clux/muslrust RUN mkdir /source WORKDIR /source COPY . . RUN cargo build --release RUN strip ./target/x86_64-unknown-linux-musl/release/myapp FROM scratch COPY --from=0 /source/target/x86_64-unknown-linux-musl/release/myapp / CMD ["./myapp"] Image compatible with cloud foundry: FROM rust:1.35 WORKDIR /usr/src/myapp COPY . . RUN cargo build --release FROM debian:latest RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y openssl ca-certificates COPY --from=0 /usr/src/myapp/target/release/myapp / CMD ["./myapp"]

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: https://nbari.com/post/galera/ 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; Doing a heavy DDL (ALTER): SELECT * FROM information_schema.processlist WHERE command != 'Sleep' AND info LIKE 'alter%' AND time >= 2 ORDER BY time DESC, id LIMIT 1; DDL stands for data definition language. It is a set of SQL statements that work on the database as a whole, rather than an individual table or row.

pigz

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

zsh

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 - Or:

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"

DoH Firefox

Open firefox and type: about:config Search for: network.trr.uri Probably you already have: https://mozilla.cloudflare-dns.com/dns-query If not add it or use something like: https://cloudflare-dns.com/dns-query https://dns.quad9.net/dns-query Then enable network.trr.mode by setting it to 2 Set network.trr.mode to 2 make DNS Over HTTPS the browser’s first choice but use regular DNS as a fallback (0 is “off by default”, 1 lets Firefox pick whichever is faster, 3 for TRR only mode, 5 to explicitly turn it off).

osascript

In macOS, to find a path of an application, for example Chromium: $ osascript -e 'POSIX path of (path to application "Chromium")'

Galera

To periodically check status of the cluster, create a script (/tmp/xx): #!/bin/sh mysql -e \ "SHOW GLOBAL STATUS WHERE Variable_name IN ( 'wsrep_cert_deps_distance', 'wsrep_cluster_size', 'wsrep_cluster_status', 'wsrep_connected', 'wsrep_evs_delayed', 'wsrep_flow_control_paused', 'wsrep_flow_control_paused_ns', 'wsrep_flow_control_recv', 'wsrep_flow_control_sent', 'wsrep_local_index', 'wsrep_local_state', 'wsrep_local_state_comment', 'wsrep_ready', 'wsrep_replicated', 'wsrep_replicated_bytes');" if credentials are in a custom path: mysql --defaults-file=/path/to/.my.cnf -s -e And run it with: watch sh /tmp/xx If single node alive (ERROR 1047 WSREP has not yet prepared node for application use):