bash script boilerplate

#!/usr/bin/env bash

set -o nounset
set -o errexit
set -o pipefail
IFS=$'\n\t'

main(){

}

main

cheatsheets

vpn route issue

sudo route flush

traceroute

traceroute -T -p 80 -n 10.0.5.4

ansible: add authorized key(s) to host(s)

ANSIBLE_HOST_KEY_CHECKING=false ansible all -b -u ec2-user -i 10.23.1.41,10.23.1.108,10.23.1.175, -m authorized_key -a "key=https://github.com/tphummel.keys user=ec2-user"

CIDR

  • /8: 10.x.x.x. 16.7MM usable IPs
  • /16: 10.0.x.x. 65,500 usable
  • /24: 10.0.0.x. 254 usable
  • /25: 126 usable
  • /26: 62 usable
  • /27: 30 usable
  • /28: 14 usable
  • /29: 6 usable

ref

Chrome Screenshot of entire window 

(including below the vertical scroll - not all pages will work. SPAs which do clever viewport optimizations sometimes don’t work)

command+option+j. command+shift+p # then type "Capture full size screenshot"

sed global find/replace

sed -i -e 's/few/asd/g' hello.txt

useful curl flags

  • -s silence progress info
  • Curl with redirects: -L
  • curl headers only: -I -X GET
  • curl insecure: -k
  • curl: --max-redirs

start ssh agent

eval "$(ssh-agent -s)"

add key to ssh agent

ssh-add -K ~/.ssh/id_rsa

remove host from known hosts

ssh-keygen -R <hostname>
ssh-keygen -R myhost.mydomain.com

find things listening on 8800

netstat -anp | grep -i 8800
ps -ef | grep -i 8800

systemd

systemctl stop docker
journalctl -f -u docker --since=1hr

find files by size

find / -size +1G

find files by name

find . -name test.png

recursively search files for a word

grep -nir "ldap" .

combine stdout, stderr

2>&1

awk print field space delimited

awk '{print $5}'

Tar, untar

https://tarball.guru/

create tarball of single file

tar -zcvf date-range-osx64.tar.gz date-range-osx64

Show merged pull requests between two SHAs

git log --oneline  8da11b6c32..ad5d336f1 | grep Merg
git log --oneline  8da11b6c32..HEAD | grep Merg

git delete remote branch

git push -d origin my-branc

git delete local branch

git branch -D my-branc

mac osx keyboard commands

apple+f2 # focus apple menu

set macosx wifi without a mouse

networksetup -listallhardwareports
networksetup -setairportnetwork en1 SSID password
networksetup -getairportnwor

list all consul services

curl -k -L host:8500/v1/catalog/services | jq
curl -k -L host:8500/v1/agent/services | jq

deregister consul service

curl -k -L -X PUT host:8500/v1/agent/services | jq

heredoc cat to file

cat > outfile.txt <<EOF
>some text
>to save
>EOF
cat > main.tf <<EOF
provider "oci" {
  tenancy_ocid = "ocid1.tenancy.oc1..aaaaaaaayzxt7lzjz34ttvgs7a7ht6ouzidp4c7y7kycd6corklhi46hl6ta"
  user_ocid = "<<replace with your OCID from web console>>"
  fingerprint = "<<replace with your key fingerprint - can find in web console>>"
  private_key_path = "~/.oci/oci_api_key.pem"
  region = "us-ashburn-1"
}
EOF

cat > hello.txt <<EOF
hello
EOF

signaling

sudo kill -SIGUSR1 <pid>

data normalization

  • 1NF: All columns contain only a single value (no sets). 
  • 2NF: 1NF and every non-key column depends on the entire candidate key. 
  • 3NF: 2NF and every non-key column must not provide a fact about another non-key column

Sql join reference. Venn diagrams

restart mcafee endpoint protection

for i in $(ps aux | grep "[M]cAfee" | awk '{print $2}'); do sudo kill -9 $i; done

more links