Skip to content

Instantly share code, notes, and snippets.

{
"Statement": [
{
"Sid": "PackerAMIAccess",
"Action": [
"ec2:CreateImage",
"ec2:RegisterImage",
"ec2:DescribeImages"
],
"Effect": "Allow",
#!/bin/bash
rdom () { local IFS=\> ; read -d \< E C ;}
base_ami=$(while rdom; do
if [[ $E = description ]]; then
if [[ $C =~ ^ami- ]]; then
echo $C
fi
fi
done < /var/lib/jenkins/jobs/packer-base/lastSuccessful/build.xml | head -n 1)
#!/bin/bash
# Debian package dependencies: html-xml-utils qprint w3m
parcel=$1
from=$2
to=$3
tmp=/tmp/parcelforce_$parcel
@nickrw
nickrw / find-access-key-by-id.sh
Created September 2, 2014 14:39
Finds the IAM user that owns an AWS access key
#!/bin/sh
# Usage: ./find-access-key-by-id.sh <ACCESS KEY ID>
# Dependencies:
# * awscli (pip install awscli)
# * jq (https://github.com/stedolan/jq)
MYSTERY_KEY=$1
users=$(aws iam list-users | jq -r .Users[].UserName)

Keybase proof

I hereby claim:

  • I am nickrw on github.
  • I am nickrw (https://keybase.io/nickrw) on keybase.
  • I have a public key whose fingerprint is B4D5 7034 97E0 96A6 EEA8 4CDE DE30 8C8E E20F B087

To claim this, I am signing this object:

@nickrw
nickrw / resolve-ec2
Last active August 29, 2015 14:16
resolve-ec2 - turns command line parameters into IP addresses (Name tags or instance IDs). Intended to be used in conjunction with ssh-ec2 and mux
#!/usr/bin/env python
from boto import ec2
from functools import wraps
import re
def ip4(wrapped_func):
def _dec(request, *args, **kwargs):
response = wrapped_func(request, *args, **kwargs)
return [i.private_ip_address for i in response]
@nickrw
nickrw / mux
Created March 3, 2015 17:03
mux - takes a session name (optional) and list of hosts - then creates a new tmux session and opens SSH connections to the hosts in split panes
#!/bin/bash
ssh="ssh -o StrictHostKeyChecking=no"
function split_tmux() {
session=$1
shift
count=$(echo $@ | tr ' ' '\n' | wc -l)
echo "Starting session to $count hosts in $session: [$@]"
session="$session ($count)"
@nickrw
nickrw / ssh-ec2
Created March 3, 2015 17:04
ssh-ec2 - designed as an alias replacement of ssh. Will try and convert tags or instance IDs to IPs, and opens sessions in tmux if more than one result is returned
#!/bin/bash
try_ec2="$(resolve-ec2 $@)"
if [[ -z $try_ec2 ]]; then
ssh $@
else
if [[ $(echo "$try_ec2" | wc -l ) -gt 1 ]]; then
mux $1 $try_ec2
else
ssh $try_ec2
@nickrw
nickrw / sshv
Created January 23, 2013 02:12
#!/bin/bash
# A quick and dirty script for quickly SSHing to local vagrant virtual machines.
# It assumes default Vagrant port forwards. Your first VM is at 2222, your second
# is at 2200. Anything more than that and you're in trouble.
# Why? Because:
#
# $ ( time vagrant ssh -c echo ) 2>&1 | grep real
# real 0m4.870s
@nickrw
nickrw / .vimrc
Last active December 11, 2015 14:49
" Don't enter vi-compatible mode if called as 'vi' instead of 'vim'
set nocompatible
" Show the mode (duh)
set showmode
" Syntax hilighting (duh)
syntax on
" Allow edited files to set modes in a modeline.