Skip to content

Instantly share code, notes, and snippets.

View seventhskye's full-sized avatar

Seventh Skye Limited seventhskye

View GitHub Profile
@seventhskye
seventhskye / create_image.sh
Created July 27, 2016 10:43
Creates an Amazon Machine Image.
#!/bin/bash
aws ec2 create-image --instance-id $(curl -s http://169.254.169.254/latest/meta-data/instance-id) --name image-$(date +'%s')
@seventhskye
seventhskye / lights_out.sh
Last active July 23, 2016 05:37
A script to turn all instances off.
#!/bin/bash
# The TAG_KEY and TAG_VALUE environment variables
# can be set before running the script otherwise the
# default are used.
IDS`aws ec2 describe-instances \
--filter "Name=tag:${TAG_KEY:-ScheduledUptime},Values=${TAG_VALUE:-True}" \
--query 'Reservations[*].Instances[*].[InstanceId]' \
--output text`
@seventhskye
seventhskye / aws_s3_backup
Created June 7, 2016 12:34
Script to upload or download a current working directory to an s3 bucket. Script assumes that the present working directory will be the name of the s3 directory
#!/bin/bash
if [ $# -eq 0 ]; then
echo "Usage: $@ upload|download"
if [ "$BUCKET_NAME" == "" ]; then
echo "variable \$BUCKET_NAME name must be set."
fi
else
DIR=`basename ${PWD}`
aws configure --profile cloud-backup
@seventhskye
seventhskye / lights_on.sh
Last active July 23, 2016 05:37
A script to collect InstanceIds from AWS by a tag: ScheduledUptime in this case. The list can then be used for other tasks such as shutting down instances.
#!/bin/bash
# The TAG_KEY and TAG_VALUE environment variables
# can be set before running the script otherwise the
# default are used.
IDS`aws ec2 describe-instances \
--filter "Name=tag:${TAG_KEY:-ScheduledUptime},Values=${TAG_VALUE:-True}" \
--query 'Reservations[*].Instances[*].[InstanceId]' \
--output text`
@seventhskye
seventhskye / clean_docker
Last active May 26, 2016 10:32
Removes all docker images and containers.
#!/bin/bash
# Stop all containers
docker kill $(docker ps -a -q)
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)
@seventhskye
seventhskye / Makedocker
Last active May 25, 2016 13:26
A Makefile for docker images.
DATE = $(shell date)
NAME = dcrbsltd/image
VERSION = 1
all: build
build:
docker build -t $(NAME):$(VERSION) --rm .
tag_latest:
#!/bin/sh
### BEGIN INIT INFO
# Provides: dockercompose
# Required-Start: $docker
# Required-Stop: $docker
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Docker Services
### END INIT INFO
@seventhskye
seventhskye / functions
Created March 16, 2016 09:20
A library of bash functions to use for Amazon Web Services CloudFormation deployments.
#!/bin/bash
# Abort with exit and message
# Used for testing
function abort()
{
echo " *** ERROR $@"
exit 1
}
@seventhskye
seventhskye / get_url.sh
Last active March 11, 2016 04:45
A bash while loop to get a URL from $PROTOCOL, $HOST and $DNS_DOMAIN environment variables.
#!/bin/bash
DNS_DOMAIN=${DNS_DOMAIN:-example.com}
HOST=${HOST:-www}
HOSTNAME=$HOST.$DNS_DOMAIN
PROTOCOL=${PROTOCOL:-https}
URL=$PROTOCOL://$HOSTNAME
echo " --> Testing for $URL"
# Number of requests
TIMEOUT=30
# Time to wait between requests
@seventhskye
seventhskye / nokogiri.sh
Created January 3, 2016 00:24
A shell script to install nokogiri prequistes.
#!/bin/bash
sudo yum install -y gcc libxml2 libxml2-devel libxslt libxslt-devel