Skip to content

Instantly share code, notes, and snippets.

Avatar

John Place UnixSage

View GitHub Profile
@UnixSage
UnixSage / selectiveDump.sh
Created Jul 30, 2021
Shell script that calls dump with an exclude list
View selectiveDump.sh
#!/bin/sh
if [ $# = 2 ] ; then
NODENAME=$1
LEVEL=$2
elif [ $# = 1 ] ; then
NODENAME=$HOSTNAME
LEVEL=$1
else
NODENAME=$HOSTNAME
@UnixSage
UnixSage / PurgeOrphanedPacker.py
Created Apr 15, 2021
AWS Lambda function that will stop and eventually terminate instances that have packer keys attached to them .
View PurgeOrphanedPacker.py
#!/usr/bin/env python3
import datetime
import pytz
import boto3
def lambda_handler(event, context):
TerminateDelayDays = 3
StopDelayDays = 1
@UnixSage
UnixSage / RotateAwsCreds.py
Created Mar 2, 2021
Handy of you have multiple aws accounts, utility that interrogates your aws config and generates aws-vault command lines and passwords to facilitate secret rotation.
View RotateAwsCreds.py
#!/usr/bin/env python3
import configparser
import re
import string
from random import choice
from os.path import expanduser
PasswordLength = 32
SpecialCount = 4
@UnixSage
UnixSage / SES-Send.sh
Created Sep 17, 2020
Send email via AWS SES from the command line
View SES-Send.sh
#!/bin/bash
DOMAIN="example.com"
MAILFROM="cmdline@${DOMAIN}"
MAILTO="someone@example.com"
SUBJECT="Amazon SES SMTP Test from ${HOSTNAME}"
USER="AWSKEY"
PASSWORD="AWSSMTPPASSWORD"
SMTPHOST="email-smtp.us-east-1.amazonaws.com:587"
@UnixSage
UnixSage / CertBotManualAuthHook.sh
Last active May 5, 2020
Manual Script for CertBot for manual DNS Changes...
View CertBotManualAuthHook.sh
#!/bin/sh
echo "Domain: _acme-challenge.${CERTBOT_DOMAIN}" > /tmp/Manual.log
echo "Secret: ${CERTBOT_VALIDATION}" >> /tmp/Manual.log
echo "Looking for /tmp/done.$$" >> /tmp/Manual.log
while [ ! -f /tmp/done.$$ ]
do
sleep 2
@UnixSage
UnixSage / CalcHours.py
Last active Aug 1, 2020
Evenly split arbitrary groups of hours evenly across work days in a month
View CalcHours.py
#!/usr/bin/env python3
import calendar, datetime, holidays
import math
import os, json
# hours.json format
#
# {
# "Client1": 116,
@UnixSage
UnixSage / CertBotNearlyFreeSpeechAuthHook.sh
Last active May 8, 2021
Drop in script for CertBot's --manual-auth-hook switch for DNS Hosted at NearlyFreeSpeech.com
View CertBotNearlyFreeSpeechAuthHook.sh
#!/bin/bash
API_KEY="##NFS-API-KEY##"
LOGIN="##NFS-USER##"
updatedns() {
OLDDATA=`dig @${NAMESERVER} -t txt +noall +answer ${DNSRECORD}.${CERTBOT_DOMAIN} | awk '{gsub("\"",""); print $5}'`
for FUNCTION in removeRR addRR ; do
echo "Running ${FUNCTION}"
@UnixSage
UnixSage / GetBitBucketRepos.sh
Created Apr 7, 2020
Simple Script to get a list of BitBucket repos for a given team
View GetBitBucketRepos.sh
#!/bin/bash
USER="##USER_NAME_NOT_EMAIL"
SECRET="##SECRET##"
TEAM="##TEAMNAME##"
CACHE="/tmp/repolist.$$"
REPOFILE="/tmp/repolist.txt"
URL="https://api.bitbucket.org/2.0/repositories/${TEAM}?pagelen=100"
@UnixSage
UnixSage / CertBotDuckDNS-AuthHook.sh
Last active Nov 13, 2019
Script to use with CertBot's --manual-auth-hook switch
View CertBotDuckDNS-AuthHook.sh
#!/bin/sh
TOKEN="Your-Duck-DNS-Token"
BASEDOMAIN=`echo ${CERTBOT_DOMAIN} | awk -F. '{OFS="."; print $(NF-1),$(NF)}'`
echo $CERTBOT_DOMAIN
curl "https://www.duckdns.org/update?domains=${CERTBOT_DOMAIN}&token=${TOKEN}&txt=${CERTBOT_VALIDATION}"
@UnixSage
UnixSage / send2s3.sh
Last active Mar 5, 2021
Simple shell script that uses curl to send a file to s3. Useful when you do not want to load the awscli for a simple job. May have to adjust mime types according to need.
View send2s3.sh
#!/bin/sh
if [ $# -ne 1 ] ; then
echo "Need File Name"
exit
fi
s3AccessKey="##ACCESS##"
s3SecretKey="##SECRET##"
s3Bucket="data.example.com"