Skip to content

Instantly share code, notes, and snippets.

View gene1wood's full-sized avatar
🎩

Gene Wood gene1wood

🎩
View GitHub Profile
@gene1wood
gene1wood / maint.conf
Last active August 29, 2015 13:56
Apache config to serve a maintenance page
<VirtualHost 204.246.122.74:80>
ServerAdmin root@localhost
DocumentRoot "/var/www"
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} !=503
RewriteRule ^(.*)$ /$1 [R=503,L]
ErrorDocument 503 /maint.html
Alias /maint.html /var/www/html/maint.html
@gene1wood
gene1wood / maint.html
Created February 15, 2014 00:06
A maintenance page
<html><head><title>This site is undergoing planned maintenance</title></head><body><h1>This site is undergoing planned maintenance</h1><p>This maintenance which begain Saturday February 22nd should conclude around 2pm</p></body></html>
@gene1wood
gene1wood / config_file_and_command_line_arguments.py
Last active April 14, 2023 18:55
An example of how to use a config file which is overridden by command line arguments in Python.
#!/usr/bin/env python
import ConfigParser
import argparse
import logging
import os
def type_loglevel(level):
try:
result = getattr(logging, level.upper())
@gene1wood
gene1wood / getmodulus.sh
Last active August 29, 2015 14:00
Determine the modulus of a certificate, key or certificate request and output it for the purposes of comparing them to confirm they match
#!/bin/bash
if grep -- ' PRIVATE KEY-' "$1" >/dev/null; then
modulus="`openssl rsa -noout -modulus -in "$1" | md5sum | awk '{print $1}'`"
elif grep -- '-BEGIN CERTIFICATE REQUEST-' "$1" >/dev/null; then
modulus="`openssl req -noout -modulus -in "$1" | md5sum | awk '{print $1}'`"
elif grep -- '-BEGIN CERTIFICATE-' "$1" >/dev/null; then
modulus="`openssl x509 -noout -modulus -in "$1" | md5sum | awk '{print $1}'`"
else
modulus="unknown"
@gene1wood
gene1wood / generate-rfc339-timestamp.py
Last active September 9, 2016 19:48
Generate RFC 3339 timestamp in Python
# http://stackoverflow.com/a/39418771/168874
from datetime import tzinfo, timedelta, datetime
import time as _time
ZERO = timedelta(0)
STDOFFSET = timedelta(seconds=-_time.timezone)
if _time.daylight:
DSTOFFSET = timedelta(seconds=-_time.altzone)
else:
@gene1wood
gene1wood / tail-chef-log-across-hosts.bash
Created May 27, 2014 21:00
Tail the chef log across multiple hosts in parallel, exiting when the chef run completes
stack=1234
hostlist="`get_hosts $stack`"
pssh -O StrictHostKeyChecking=no \
--print \
--user ec2-user \
--host "$hostlist" \
--timeout=0 \
--par=20 \
'while true; do if ! tail -1 /var/log/chef.log | sed -e "s/^/`hostname`/" | grep -v "`date +%Y-%m-%d`.*Report handlers complete"; then tail -1 /var/log/chef.log | grep "`date +%Y-%m-%d`.*Report handlers complete"; break; fi; sleep 2; done'
# The key to using pssh and sudo is the `--extra-args='-t -t' trick
pssh -H "`cat hostlist.txt`" \
--user ec2-user \
--timeout=0 \
--inline \
--par=10 \
--extra-args='-t -t -o StrictHostKeyChecking=no' \
'sudo cat /etc/shadow'
@gene1wood
gene1wood / moving_files_around.sh
Created June 13, 2014 17:55
Some old bash functions for doing parallel ssh and scp, pushing and fetching files through jump hosts and deep escaping
function multiscp {
hostlist=$1
filename=$2
tempfiletemplate="/tmp/`basename $0`-XXXXXX"
pidlistfile="`mktemp $tempfiletemplate`"
exitstatus=0
for host in $hostlist; do
scp $filename $host: &
echo "$!" >>$pidlistfile
done
@gene1wood
gene1wood / chef-server-bootstrap.sh
Created June 13, 2014 17:58
A chef server installation method in bash. This is likely now out of date with current chef server installation procedures
sudo true && curl -L https://www.opscode.com/chef/install.sh | sudo bash
sudo yum install -y git
sudo mkdir -p /var/chef/cookbooks
sudo chown root:wheel /var/chef/cookbooks
sudo chmod g+w /var/chef/cookbooks
cd /var/chef/cookbooks
git init
touch .gitignore
git add .gitignore
git commit -m "initial commit"
@gene1wood
gene1wood / get_all_instances_all_regions.py
Last active August 29, 2015 14:02
Fetch all instances across all regions
import boto.ec2
import sys
from pprint import pprint
all_regions = [x.name for x in
boto.ec2.connect_to_region('us-east-1').get_all_regions()]
instances=[]
for region in all_regions:
instances.extend(boto.ec2.connect_to_region(region).get_only_instances())