Skip to content

Instantly share code, notes, and snippets.

View ericwastaken's full-sized avatar

Eric Soto ericwastaken

View GitHub Profile
@ericwastaken
ericwastaken / delete-child-directory-contents.sh
Last active November 7, 2020 02:52
A BASH script to delete the contents of all child directories in the current path while retaining the child directories themselves.
#!/bin/bash
############################################################################
# This script iterates over each child directory from where it runs
# and deletes ALL contents of those child directories, while leaving
# the directory itself intact.
#
# Copyright 2020 Eric A. Soto, [email protected]
#
# Permission is hereby granted, free of charge, to any person obtaining a
@ericwastaken
ericwastaken / Running an ad-hoc command on multiple hosts using ansible.md
Last active November 21, 2024 21:28
Running ad-hoc Commands and Scripts on multiple hosts using Ansible

Running ad-hoc Commands and Scripts on multiple hosts using Ansible

Summary

Ansible is very helpful for automated deployments. However, it can also be used for server admin tasks against many servers by using both the Command, Shell and Script Modules.

Note: Although the process described here works with hosts that you can access via password or SSH keys, it is more convenient when working with hosts that you have SSH keys for (you don't have to enter passwords!)

License

@ericwastaken
ericwastaken / s3-setup.md
Last active September 24, 2024 13:18
How to create an S3 Bucket with Programmatic Access

How to create an S3 Bucket with Programmatic Access

Summary

This post explains how to create an AWS S3 Bucket and an IAM User with programmatic access to the bucket.

You will need access to the AWS S3 console for your account and have permissions to create new buckets and create new IAM users.

This is based on:

@ericwastaken
ericwastaken / Manual Snapshot (Backup) of an Elastic Cloud instance.md
Last active November 7, 2020 02:57
Manual Snapshot (Backup) of an Elastic Cloud instance to AWS S3
@ericwastaken
ericwastaken / rsample.sh
Created April 23, 2020 19:19
Random Sample
#!/bin/bash
############################################################################
# Random Sample - rsample.sh
#
# A utility to output a sample number of lines from
# a text file based on a percentage passed in as an
# argument.
#
# Dependencies:
@ericwastaken
ericwastaken / git-cheat-sheet.md
Last active October 28, 2021 23:58
A Cheat Sheet with some interesting GIT commands
#!/bin/bash
################################################################
# This is a script that pulls a list of IPs from AWS
# published IP list, then parses it looking for a
# specific region and service.
#
# Dependencies:
# This script needs:
# * Internet access
@ericwastaken
ericwastaken / script-with-prompt.sh
Last active January 2, 2020 21:18
Example of a BASH script that outputs some text then waits for confirmation before proceeding.
#!/bin/bash
echo "Say something here to confirm some action."
echo ""
# Wait for the user to press any KEY to proceed or allow them to Ctrl+C
read -n1 -rsp $'Press any key to continue or Ctrl+C to exit...\n'
# Do your work after this... it won't execute if the user does Ctrl+C at the prompt!
@ericwastaken
ericwastaken / remotetunnel-dn.sh
Last active December 21, 2018 05:38
Looks for a pidfile to a previously started SSH background process, then stops the process.
#!/bin/bash
# Get the directory where the script lives.
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
# Setup a variable for easy reference to the pidfile
pidfile=${SCRIPT_DIR}/tunnel.pid
# Check for our pidfile, which we expect in order to be able to control the process
if [ ! -f $pidfile ]; then
echo "Tunnel pidfile does not exist. Tunnel might not up or not known! Exiting!"
@ericwastaken
ericwastaken / remotetunnel-up.sh
Last active December 21, 2018 05:35
Establish an SSH tunnel to a remote host in the background, preserving the PID in a pidfile so it can be used to later stop the background process.
#!/bin/bash
# Get the directory where the script lives.
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
# Setup a variable for easy reference to the pidfile
pidfile=${SCRIPT_DIR}/tunnel.pid
# Check to see if there is a pidfile already...
if [ -f $pidfile ]; then
# There is, so the tunnel might be up!