Skip to content

Instantly share code, notes, and snippets.

View eekfonky's full-sized avatar

Christopher Welsh eekfonky

  • West Linton
  • 16:21 (UTC +01:00)
View GitHub Profile
@eekfonky
eekfonky / rds-apply-del-pro.sh
Created December 4, 2018 17:21
Apply RDS Deletion Protection
#!/bin/bash
# Enable extended globbing for the +(...) pattern
shopt -s extglob
## Variable Declartions ##
OUTPUT="text" # set output format
## FUNCTIONS ##
# apply Instance DB deletion protection
@eekfonky
eekfonky / stop-start-EC2.sh
Created May 15, 2018 12:11
Stop/Start EC2
#!/bin/bash
# Set variables for tags, region, SSH key location & user
# Set these 4 to appropriate values
REGION="eu-central-1"
TAG="<EC2_TAG>"
SSH="~/.ssh/<PATH_TO_FILE>"
USER="ubuntu"
# Check AWS credentials exist
@eekfonky
eekfonky / task-status.sh
Created April 13, 2018 07:51
EC2 Task Status
#!/bin/bash
region="eu-west-1"
cluster="<CLUSTER_NAME>"
## Get Task names from Cluster
task_status () {
echo "Task Name and Status:"
mapfile -t tasksInCluster < <(aws ecs list-tasks --region $region --cluster $cluster | jq -r '.taskArns[]')
for task in "${tasksInCluster[@]}"; do
aws ecs describe-tasks --region $region --cluster $cluster --tasks $task | jq -r '.tasks[].containers[] | .name + " " + .lastStatus'
@eekfonky
eekfonky / Disable-SSH-Host-Key-Checking.txt
Created March 20, 2018 11:01
Disable SSH Host Key Checking
ssh -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" user@host
@eekfonky
eekfonky / remove directories
Last active March 16, 2018 15:57
Remove all directories but not files
find -mindepth 1 -maxdepth 1 -type d -exec rm -r {} \;
@eekfonky
eekfonky / ec2StopStart.sh
Last active March 16, 2018 11:19
Stop or Start (and SSH to) EC2 instance
#!/bin/bash
# Set variables for tags, region, SSH key location & user
# Set these 4 to appropriate values
REGION="eu-central-1"
TAG="chris-sandbox"
SSH="~/.ssh/frankfurt.pem"
USER="ubuntu"
# Check AWS credentials exist
@eekfonky
eekfonky / ec2VolumeSnapshot.sh
Created March 9, 2018 11:59
Backup EBS Volume to Another Region
#!/bin/bash
# error handling
error_handler() {
echo "Error occurred in script at line: ${1}"
echo "Line exited with status: ${2}"
}
trap 'error_handler ${LINENO} $?' ERR
@eekfonky
eekfonky / .bashrc
Created February 9, 2018 07:44
.bashrc for Ubuntu
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
@eekfonky
eekfonky / EC2-snapshot
Last active December 1, 2017 22:02
Create EC2 Snapshot in source region, copy to another region copy and remove after X days
#!/bin/bash
# error handling
error_handler() {
echo "Error occurred in script at line: ${1}"
echo "Line exited with status: ${2}"
}
trap 'error_handler ${LINENO} $?' ERR
@eekfonky
eekfonky / package_to_install
Last active December 23, 2017 06:03
Add package install to bash script
package_to_install () {
# enter the package you want installed in PKG_NAME below
PKG_NAME="<PACKAGE_NAME>"
if ! type $PKG_NAME > /dev/null 2>&1; then
# check Linux package manager (yum or apt)
declare -A osInfo;
osInfo[/etc/redhat-release]=yum
osInfo[/etc/arch-release]=pacman
osInfo[/etc/gentoo-release]=emerge
osInfo[/etc/SuSE-release]=zypp