Skip to content

Instantly share code, notes, and snippets.

View gordonmurray's full-sized avatar
🍺

Gordon Murray gordonmurray

🍺
View GitHub Profile
@gordonmurray
gordonmurray / handy_aws_cli_commands.txt
Last active April 15, 2016 11:14
Handy CLI Commands
# Sync 2 S3 buckets
aws s3 sync s3://{source} s3://{destination}
# Determine size of an S3 bucket
aws s3api list-objects --bucket {s3_bucket_name} --output json --query "[sum(Contents[].Size), length(Contents[])]"
# dump large mysql DB > tested on 200gb DBs
mysqldump -h {HOST} -u {USER} -p {TABLE} --single-transaction --default-character-set=utf8 --quick --extended-insert > {FILENAME}.sql
@gordonmurray
gordonmurray / split.sh
Created April 16, 2017 18:29
A small script to take a larger text based file and break it down to several smaller files
#!/usr/bin/env bash
# A small script to take a larger text based file and break it down to several smaller files
# of 500 lines each for easier processing, keeping the headings at the top of each file
FILENAME=${1}
if [ -z ${FILENAME} ]; then
echo "Please provide a filename, for example: bash split.sh /path/to/data.csv";
else
#!/usr/bin/env bash
# white list all public IPs from an AWS region in to a security group
security_group="sg-xxxxxx"
region="eu-west-1"
port="3306"
# list the public IPs from the instances in region
public_ips=`aws ec2 describe-instances --query "Reservations[*].Instances[*].PublicIpAddress" --output=text --region=${region} | xargs`
@gordonmurray
gordonmurray / aws_elasticache.sh
Created October 6, 2017 20:21
List your aws elasticache parameter groups and show their existing parameters
# list your aws elasticache parameter groups
aws elasticache describe-cache-parameter-groups --profile=xxxxx --region=us-east-1
# list the parameters currently set in a particular aws elasticache parameter groups
aws elasticache describe-cache-parameters --profile=xxxxx --region=us-east-1 --cache-parameter-group-name=xxxxx > xxxxx.json
@gordonmurray
gordonmurray / installDocker.sh
Created February 11, 2018 18:55
Install Docker
# prerequisites for docker
apt-get update
apt-get -y install apt-transport-https
apt-get -y install ca-certificates
apt-get -y install curl
apt-get -y install software-properties-common
# docker repos
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - \
&& echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable" >> /etc/apt/sources.list.d/additional-repositories.list \
@gordonmurray
gordonmurray / convertCaddyCerts.md
Last active May 27, 2024 11:42
Steps to convert certificates generated by Caddy Server to certificates that Nginx can use

Convert Caddy Server certificates to LetsEncrypt certificates to be used by Nginx

Caddy

When using Caddy Server, it stores certificates in ~/.caddy/acme/acme-v01.api.letsencrypt.org/sites/{your domain name}/

3 files are stored in the folder called:

  • {yourdomain}.crt
  • {yourdomain}.json
  • {yourdomain}.key
@gordonmurray
gordonmurray / aws_cli_create_ec2_instance.sh
Last active April 2, 2022 07:25
AWS CLI steps to create a basic EC2 web server
#!/usr/bin/env bash
# The following assumes you have an AWS account with the AWS CLI installed locally
# It will ask which VPC and Subnets to use
# Show the commands being executed
set -ex
# AWS region
REGION="eu-west-1"
@gordonmurray
gordonmurray / aws_ecs_cluster.sh
Last active November 24, 2019 11:26
Create an AWS ECS Cluster
# Moved to a Repo here instead and added some additional files
https://github.com/gordonmurray/ecs_cluster_using_aws_cli
@gordonmurray
gordonmurray / aws_disable_auto_minor_version_upgrades.sh
Last active October 30, 2023 17:05
Simple script to list all RDS instances and then disable Automatic Minor Version Upgrades
# Simple script to list all RDS instances and then disable Automatic Minor Version Upgrades
# list RDS instances to a file
aws rds --region eu-west-1 describe-db-instances | jq -r '.DBInstances[].DBInstanceIdentifier' > rds.log
# loop over the items in the file, disable auto minor version upgrades
while read rds; do
aws rds modify-db-instance --region eu-west-1 --db-instance-identifier ${rds} --no-auto-minor-version-upgrade
sleep 5
done <rds.log
@gordonmurray
gordonmurray / rds_random_maintenance_windows.sh
Created December 18, 2019 10:10
Set random maintenance windows on all RDS instances within limits
#!/usr/bin/env bash
set -xe
REGION="eu-west-1"
# list RDS instances to a file
aws rds --region ${REGION} describe-db-instances | jq -r '.DBInstances[].DBInstanceIdentifier' > rds.log
# loop over the rds instances in the file