View utils.sh
# minion.conf
# The external pillars permitted to be used on-demand using pillar.ext
on_demand_ext_pillar:
- libvirt
- virtkey
- saltclass
id: dontpanic
View strace.sh
# http://www.thegeekstuff.com/2011/11/strace-examples/
strace -f -o /tmp/strace.log -s 2048 -p 1 & systemctl restart postgresql.service
#Then, after a couple of seconds, fg into the strace process, cancel it, and then
#see it the strace.log helps.
strace -e trace=open,read ls /home
strace $(pidof apache2 | sed 's/\([0-9]*\)/\-p \1/g')
View yaml_ordered_dict.py
import yaml
import yaml.constructor
try:
# included in standard lib from Python 2.7
from collections import OrderedDict
except ImportError:
# try importing the backported drop-in replacement
# it's available on PyPI
from ordereddict import OrderedDict
View fluentd.conf
# Consider the record contains the time stamp of the event in a record key called 'timestamp'
# e.g. "timestamp": "1502217900063"
# The below will add a new record called `formatted_date` that will include an iso8601(3) formatted date string with milliseconds,
# the trick was to extract from the long epoch value the seconds & remaining milliseconds and convert it to microseconds since Time.at() accepts:
# `Time.at(seconds, microseconds_with_frac) → time`
<filter tag.*>
@type record_modifier
<record>
View hugo-build.sh
#!/usr/bin/env bash
function contains {
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && return 0; done
return 1
}
function remove_toplevel {
View cleanup-docker.sh
#!/bin/bash
# remove exited containers:
docker ps --filter status=dead --filter status=exited -aq | xargs -r docker rm -v
# remove unused images:
docker images --no-trunc | grep '<none>' | awk '{ print $3 }' | xargs -r docker rmi
# remove unused volumes:
find '/var/lib/docker/volumes/' -mindepth 1 -maxdepth 1 -type d | grep -vFf <(
View cleanup-docker.sh
#!/bin/bash
# remove exited containers:
docker ps --filter status=dead --filter status=exited -aq | xargs -r docker rm -v
# remove unused images:
docker images --no-trunc | grep '<none>' | awk '{ print $3 }' | xargs -r docker rmi
# remove unused volumes:
find '/var/lib/docker/volumes/' -mindepth 1 -maxdepth 1 -type d | grep -vFf <(
View docker-cleanup.sh
#!/bin/bash
# Do not run if removal already in progress.
pgrep "docker rm" && exit 0
# Remove Dead and Exited containers.
docker rm $(docker ps -a | grep "Dead\|Exited" | awk '{print $1}'); true
# It will fail to remove images currently in use.
docker rmi $(docker images -qf dangling=true); true
View log-all-zsh-bash-commands-syslog.md

Sending Bash and ZSH Commands to Syslog

Also posted here: http://18pct.com/sending-bash-and-zsh-commands-to-syslog/

Your bash/zsh history is great if its complete, but it doesn't capture commands across all users, sudo's, root commands etc. In particular with test environments, someone may perform a "one-off" procedure and then months later it needs to be repeated. It would be nice to be able to look up what the user did at the time, and searching through multiple, possibly truncated history files is a pain.

Tools like typescript are great if you're actively documenting, but not something you would use all the time in practice and capture more than just a history of your commands. There are third-party tools like rootsh and Snoopy that can accomplish this, but third-party tools can be overkill if all you want is a quick reference in a re

View self-extracting-shell-scripts.sh
## makeself (14k min size)
# See: https://github.com/megastep/makeself
## for real minimalists
cat <<-EOF > /tmp/myapp.sh
#!/bin/sh -e
sed -e '1,/^exit$/d' "$0" | tar xzf - && /tmp/myapp/run.sh
exit
EOF