Skip to content

Instantly share code, notes, and snippets.

View gene1wood's full-sized avatar
🎩

Gene Wood gene1wood

🎩
View GitHub Profile
@gene1wood
gene1wood / pssh-chef.sh
Created January 31, 2014 01:20
A parallel ssh command which checks the last chef run and runs it again if there was a problem.
# `get_hosts $stack` returns the ips of the instances in the named stack
# the "-t -t" extra-args works around the issue of running sudo without a tty
# the "--force-formatter" tells chef-solo to still output what it's doing even though it has no tty
stack=1234
pssh --host="`get_hosts $stack`" --timeout=0 --inline --par=10 --extra-args='-t -t -o StrictHostKeyChecking=no' --user=ec2-user 'if tail -1 /var/log/chef.log | grep FATAL; then sudo chef-solo -c /etc/chef/solo.rb -j /etc/chef/node.json --force-formatter; fi'
<div class="textwidget"><span id="nextmeeting">The next meeting will be held at Linden Street Brewery </span><span id="nojavascript">on the second Thursday of the month</span>. Social starts at 7:00pm, meeting starts at 7:30pm.
<script>
// First, checks if it isn't implemented yet.
if (!String.prototype.format) {
String.prototype.format = function() {
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != 'undefined'
? args[number]
#!/bin/bash
for i in $(eval echo {1..$1})
do
echo $(date +"%T")
if ! curl -v "https://accounts.firefox.com" -o /dev/null &>/tmp/c.out; then
cat /tmp/c.out
else
echo "success"
fi
@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 / 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 / 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"