Skip to content

Instantly share code, notes, and snippets.

View seventhskye's full-sized avatar

Seventh Skye Limited seventhskye

View GitHub Profile
@seventhskye
seventhskye / iso_8601.sh
Created September 3, 2015 14:58
ISO 8601 UTC compliant Unix datetime stamp format
#!/bin/bash
# This script generates test logs with a UTC ISO 8601
# compliant timestamp
# http://www.iso.org/iso/home/standards/iso8601.htm,
# https://en.wikipedia.org/wiki/ISO_8601
while true
do
date -u +%Y-%m-%dT%H:%M:%S%z
sleep 1
@seventhskye
seventhskye / centre_div.css
Created September 6, 2015 12:20
Centres a div, vertically and horizontally in a webpage
.centre {
width:500px;
height:500px;
position:absolute;
left:50%;
top:50%;
margin:-250px 0 0 -250px;
}
@seventhskye
seventhskye / awslogs_agent_install.sh
Last active September 8, 2015 21:46
Short script to install Amazon CloudWatch Logs agent on Debian
#!/bin/bash
echo "Usage: $0 <REGION>"
exit 1
apt-get update
wget https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py
python ./awslogs-agent-setup.py --region $1
@seventhskye
seventhskye / aws-cfn-bootstrap_install.sh
Last active October 31, 2015 11:33
Installs the aws-cfn-bootstrap helper scripts on Debian.
#!/bin/bash -ex
apt-get update
apt-get -y install python-setuptools
mkdir aws-cfn-bootstrap-latest
curl https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz | tar xz -C aws-cfn-bootstrap-latest --strip-components 1
easy_install aws-cfn-bootstrap-latest
cp -f aws-cfn-bootstrap-latest/init/ubuntu/cfn-hup /etc/init.d/ && chmod 0755 /etc/init.d/cfn-hup
update-rc.d cfn-hup defaults
service cfn-hup start
@seventhskye
seventhskye / scheduled_action.json
Created September 9, 2015 00:24
A 7am Monday to 7pm Friday development environment-esk scheduled action, to use for an AutoScaling group in a CloudFormation template.
"ScheduledActionUp": {
"Type": "AWS::AutoScaling::ScheduledAction",
"Properties": {
"AutoScalingGroupName": {
"Ref": "AutoScalingGroup"
},
"MaxSize": "1",
"MinSize": "1",
"Recurrence": "0 7 * * 1"
}
@seventhskye
seventhskye / create_image.sh
Created September 10, 2015 09:57
Bash wrapper to create an Amazon Machine Image when logged into an instance. The IAM profile or keys must have the statement specified.
#!/bin/bash
# "Statement": [
# {
# "Effect": "Allow",
# "Action": [
# "ec2:CreateImage",
# "ec2:RegisterImage"
# ],
# "Resource": "*"
# }
@seventhskye
seventhskye / create_ssl_cert.sh
Created September 30, 2015 11:54
Quick script to generate a self signed certificate. See https://en.wikipedia.org/wiki/Certificate_signing_request for details of the CSR parameters.
#!/bin/bash
if [ $# -eq 0 ]; then
echo "Usage: $0 <CERT_NAME>"
echo "e.g. $0 example.com"
else
openssl genrsa -des3 -passout pass:x -out $1.pass.key 2048
openssl rsa -passin pass:x -in $1.pass.key -out $1.key
rm $1.pass.key
openssl req -new -key $1.key -out $1.csr
fi
@seventhskye
seventhskye / instance_id.sh
Created October 6, 2015 08:54
A script to find the instance-id and region from the metadata of an Amazon based instance.
#!/bin/bash
# Get Instance Details
INSTANCE_ID=$(wget -q -O- http://169.254.169.254/latest/meta-data/instance-id)
REGION=$(wget -q -O- http://169.254.169.254/latest/meta-data/placement/availability-zone | sed -e 's/\([1-9]\).$/\1/g')
@seventhskye
seventhskye / register_or_deregister_with_elb
Last active October 6, 2015 10:47
A short script to register or deregister an instance with an Elastic Load-balancer. Will require IAM permissions and is assumed to be run from the instance.
#!/bin/bash
if [ $# -eq 0 ]; then
echo "Usage: $0 register|deregister <LOAD_BALANCER_NAME>"
echo "e.g. $0 register load-balancer-name"
else
INSTANCE_ID=$(wget -q -O- http://169.254.169.254/latest/meta-data/instance-id)
REGION=$(wget -q -O- http://169.254.169.254/latest/meta-data/placement/availability-zone | sed -e 's/\([1-9]\).$/\1/g')
if [ "$1" == "deregister" ]; then
aws elb $1-instances-from-load-balancer \
--load-balancer-name $2 \
@seventhskye
seventhskye / register_deregister_userdata.json
Last active October 6, 2015 13:52
Userdata snippet to add register and deregister commands to an ubuntu instance in aws
"cat << EOF > /etc/init.d/register_with_elb\n",
"#!/bin/bash\n",
"aws elb register-instances-with-load-balancer --load-balancer-name ",
{
"Ref": "LoadBalancerName"
},
" --instances $(wget -q -O- http://169.254.169.254/latest/meta-data/instance-id) --region ",
{
"Ref": "AWS::Region"
},