Skip to content

Instantly share code, notes, and snippets.

@xcsrz
xcsrz / nodes.sh
Created July 18, 2014 19:07
This gets the information to identify the master node in Elasticsearch 0.90.*
#!/bin/bash
curl -s "http://localhost:9200/_cluster/state?pretty=true&filter_metadata=true&filter_indices=true&filter_routing_table=true"
@xcsrz
xcsrz / GetDockerImage.sh
Created November 3, 2014 18:39
Get a docker image from a remote host imported onto the localhost in the most direct way possible.
#!/bin/bash
#### either replace $USERNAME, $DOCKERHOST and $IMAGENAME in the command
#### or adjust and use the following export commands before running this as a script
# export USERNAME=xcsrz
# export DOCKERHOST=1.1.1.1
# export IMAGENAME=xcsrz/forth
ssh $USERNAME@$DOCKERHOST "sudo docker save $IMAGENAME | gzip -c" | gunzip -c | docker load
@xcsrz
xcsrz / pageTimer.rb
Created November 5, 2014 20:23
Just a little script to time page requests (no assets, just the single URL). It runs via /usr/bin/ruby which is present on all macs and most posix systems these days. If you're using rvm you'll probably want to change that.
#!/usr/bin/ruby
$url = ARGV[0]
$rounds = ARGV[1] || 10
loadTimes = []
puts "fetching page #{$rounds} times ..."
$rounds.to_i.times do
print "."
loadTimes << (`curl -w '%{time_total}\n' -o /dev/null -s "#{$url}"`).to_f
@xcsrz
xcsrz / flush-old-docker-containers.sh
Last active August 29, 2015 14:09
If you run into a situation where you have thousands or tens of thousands of dead containers and you run the usual docker rm `docker ps -a -q` either docker will bomb saying too many arguments or you'll see that as the list of containers being killed grows the process slows down. It seems the docker process amasses all the open files until it's …
while [[ `docker ps -a -q | wc -l` -gt `docker ps -q | wc -l` ]]; do docker rm ` docker ps -a -q | head -n 25`; done
@xcsrz
xcsrz / xknife
Created November 21, 2014 17:47
A script to help abbreviate knife commands.
#!/usr/bin/ruby
require 'optparse'
envs = []
roles = []
user = ENV['XKNIFE_SSH_USER'] || nil
debug = false
if ENV['XKNIFE_CHEF_REPO']
@xcsrz
xcsrz / elasticsearch-node-shard-counter.rb
Created January 7, 2015 19:13
Prints out how how many primary and secondary shards on each node in an Elasticsearch Cluster.
#!/usr/bin/env ruby
require "json"
state = JSON.parse `curl localhost:9200/_cluster/state`
dets = {}
state["nodes"].each do |name, details|
dets[name] = { "name" => details["name"], "address" => details["transport_address"] }
end
@xcsrz
xcsrz / guid.sh
Created February 27, 2015 22:10
Quick access to a uuid generator using ruby inline
ruby -e 'require "securerandom"; print SecureRandom.uuid;'
@xcsrz
xcsrz / create-ssl-cert.sh
Last active October 28, 2015 23:19
This script creates the .key and .csr files using the bare minimum information. It's only argument is the domain name to be secured. Prepend "*." for wildcard domain certificates. Customize the DEFAULT_ORGNAME and DEFAULT_ORGCOUNTRY setting variables at the top before use. Environment variable overrides are ORGNAME and ORGCOUNTRY.
#!/bin/bash
DEFAULT_ORGNAME="xcsrz"
DEFAULT_ORGCOUNTRY="US"
if [ -t $1 ]; then
echo "you must provide a domain name (don't forget the asterisk if it's for a wildcard certificate"
echo ""
echo "Usage:"
echo " ${0} DOMAIN"
@xcsrz
xcsrz / mysql-logging.sql
Last active November 17, 2015 02:57
Query mysql logs
SET global general_log = 1;
SET global log_output = 'table';
-- and then
select * from mysql.general_log order by event_time desc
@xcsrz
xcsrz / getInside.sh
Last active November 17, 2015 02:59
A bash function to get inside a running docker container ... still needs tweaking, requires nsenter ( https://github.com/jpetazzo/nsenter )
getInside() {
# pass in a container ID
CONTID=$1;
# This prints out export commands you can paste into the terminal once inside the container - not always needed
sudo docker inspect $CONTID | awk '/(PATTERN FOR ENV VARIABLES YOU CARE ABOUT)/ { gsub(/[",]/,"",$1); print "export " $1 } '
# Get the process ID
PID=$(sudo docker inspect --format {{.State.Pid}} $CONTID );
# Status message
echo "Entering container $CONTID with PID $PID";
# Enter the container