Skip to content

Instantly share code, notes, and snippets.

View joeljacobs's full-sized avatar

Joel Jacobs joeljacobs

  • Perfect Pitch Tehnologies
  • Utah
View GitHub Profile
@joeljacobs
joeljacobs / time_elapsed.sh
Last active March 3, 2017 23:48
Bash Timing Function. Takes <start_time> <title> [<timezone}]
#!/bin/bash
#Outputs
# <title> Start: 4:30:01pm End: 4:33:05pm Elapsed: 0:03:04
# Script behaves same as function. i.e. you can copy the function out.
time_elapsed(){
timezone=${3-"America/Denver"} #Defaults to Mountain Time
resume_time=$(date)
@joeljacobs
joeljacobs / puppet_notes.txt
Last active May 4, 2017 23:34
Puppet Zero Padding sprintf each split match
#$pp_num_raw = split($::hostname, 'pp')[1]
#$pp_num = sprintf("%0#2i", $pp_num_raw)
#$pp_num = split($::hostname, 'pp')[1].sprintf"%0#2i"
#$pp_num = sprintf("%0#2i", "${::hostname}".split('pp')[1])
$pp_num = sprintf("%0#2i", "${::hostname}".match(/(pp)([0-9]+)([^[0-9]]*)/)[2])
["api", "live", "upload"].each|$local_suffix|{
file { "/etc/nginx/conf.d/ppcc.local.$local_suffix":
content => template("pp_nginx_manager/conf.d/ppcc.local.${local_suffix}.erb"),
ensure => present,
}
@joeljacobs
joeljacobs / Swarm docker ps format
Last active August 17, 2017 02:36
Ridiculous docker ps format for Swarm
docker ps --format 'table {{.ID}}|{{.Image}}|{{.Command}}|{{.RunningFor}}|{{.Status}}|{{.Ports}}|{{.Names}}'|sed -e 's/dev\.perfectpitchtech\.com:4567\/service\///' -e 's/\(^.*|.*|.*|.*|.*|\)\(.*\)\(|[^|]*$\)/\1+\2+\3/' -e 's/\(\|[a-z0-9]\{3\}[^\.]+\)\(\.[^|]\{4\}\)[^|]*$/\1\2\.\.\./'|(while read jerk; do ports=$(echo "$jerk"|sed 's/\(^.*+\)\(.*\)\(+.*$\)/\2/');newports=$(echo $ports|sed -e 's/\/[ut][dc]p\(,\)* */\1/g'|cut -c 1-12); echo $jerk|sed "s/+.*+/${newports}.../"; done)|column -tns "|"
# du with only 1 filesystem
du -achxd1 |sort -h
# Ubuntu14 Service Management
update-rc.d -f <service> remove
service --status-all
filldisk(){
DISKNUM=$2
if [[ ! $2 =~ [0-9] ]]; then echo must specify disk num as 2nd arg;return 1;fi
SKIP="${3:-0}"
BS="${4:-4}"
SIZE=$(( (2 * 1024 *1024) - ($SKIP * 1024) ))
gnumfmt --format=%.3f --to=iec --from=iec ${SIZE}M\
case $1 in
random)
@joeljacobs
joeljacobs / release_non-swarm.sh
Created September 16, 2017 00:07
Bash threaded parallel with getopt example
#!/bin/bash
OPTS=`getopt -o vhns: --long service:,sha:,server: -n 'parse-options' -- "$@"`
fail=false
if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi
eval set -- "$OPTS"
servers=()
while true; do
@joeljacobs
joeljacobs / zfsswap
Created April 17, 2018 22:02
Add ZFS swap
function zfsswap { pool=${1-rpool}; gigs=${2-50};zfs create -V ${gigs}G -b $(getconf PAGESIZE) -o compression=zle -o logbias=throughput -o sync=always -o primarycache=metadata -o secondarycache=none -o com.sun:auto-snapshot=false $pool/swap && mkswap -f /dev/zvol/$pool/swap && echo /dev/zvol/$pool/swap none swap defaults 0 0 >> /etc/fstab && swapon -av ; }
@joeljacobs
joeljacobs / vmmem
Last active April 18, 2018 01:56
virsh mem
function vmmem { free="$(free -h)";echo "$free";memtotal=0 ; for i in $(virsh list --name); do mem=$(( $(virsh dommemstat $i |head -1|cut -d " " -f 2) /1024/1024));memtotal=$(( $memtotal + $mem)); printf "%-20s%10s\n" $i $mem; done; echo " Total VM ${memtotal}G"; echo " Difference: $(( $(echo "$free" |grep "Mem:"|cut -d " " -f 12|rev|cut -c 2-|rev) - $memtotal))G"|sort -V; }
@joeljacobs
joeljacobs / pibackup
Last active December 22, 2020 06:56
Modified Script to Backup All partitions of a RaspberryPi. Added incremental rsync.
#!/bin/bash
if [[ $1 == "" ]]
then
echo "You must specify the copy-to device as the first argument"
echo "You may also specify a source device as the 2nd argument. Default= mmcblk0"
echo "If you want no prompts and incremental, specify -a as the last argument"
echo "i.e.: backup sda [nbd0] [-a]"
@joeljacobs
joeljacobs / externalip.sh
Created February 7, 2018 20:15
External IP script (from Jon)
#!/bin/bash
## Get my external IP
timeout=2 # seconds to wait for a reply before trying next server
#verbose=1 # prints which server was used to STDERR
dnslist=(
"dig +short myip.opendns.com @resolver1.opendns.com"
"dig +short myip.opendns.com @resolver2.opendns.com"