Skip to content

Instantly share code, notes, and snippets.

@whereisaaron
whereisaaron / pfx-to-crt-and-key.sh
Last active March 5, 2024 18:13
Extract a crt file (PEM), key file, and chain bundle from a PFX file, prompts for password or use PFXPASSWORD environment variable
#!/bin/bash
#------------------
# Extract the key, certficiate, and chain in PEM format from a PFX format file
#
# Must supply the input pfx file
PFX_PATH="$1"
if [ "${PFX_PATH}" == "" ]; then
echo "Must supply pfx file path"
exit 1
@whereisaaron
whereisaaron / Dockerfile
Last active September 12, 2023 14:57
Support for automatic restarting for Apache after mod_md renews a certificate and invokes `MDMessageCmd renewed` command
#--------------------------------------
# Build md_event command
#--------------------------------------
FROM gcc:bullseye as build
COPY ./md_event.c .
RUN gcc md_event.c -o md_event
#--------------------------------------
# Apache container
#--------------------------------------
@whereisaaron
whereisaaron / get-aws-eks-node-ami-versions.sh
Created November 13, 2022 04:11
Get the versions names for AWS EKS Kubernetes node AMIs as listed in releases at https://github.com/awslabs/amazon-eks-ami/releases
#!/bin/bash
set -e -u -o pipefail
#
# Get the versions names for node AMIs as listed in AMI releases
# https://github.com/awslabs/amazon-eks-ami/releases
#
: ${CLUSTER:=${1?"Must specify cluster name"}}
@whereisaaron
whereisaaron / CleanUpOrphanedSubplansAndLogs.sql
Created November 12, 2022 11:27
Clean up orphaned SQL Server Maintenance Plan subplans and their logs, use this if you get a conflict error deleting a job
--
-- Clean up orphaned Maintenance Plan subplans and their logs
-- Use this if you get a conflict error deleting a job
--
use [msdb]
GO
delete from msdb..sysmaintplan_log
where plan_id not in (
@whereisaaron
whereisaaron / create-dummy-files.sh
Created October 31, 2022 17:52
Create a collection of dummy files to use up space
#!/bin/bash -e
START=${1:-1}
END=${2:-10}
for i in $(seq ${START} ${END}); do
filename=$(printf 'dummy-10GiB-%03d.bin' $i)
if [[ -f ${filename} ]]; then
echo "Dummy file ${filename} already exists"
else
@whereisaaron
whereisaaron / create-self-signed-cert.sh
Created August 4, 2022 09:12
Create a self-signed certificate using openssl to bootstrap a server
#!/bin/bash
set -eu
#
# Create a self-signed certificate to bootstrap a server
# Ref: https://devopscube.com/create-self-signed-certificates-openssl/
#
if [ "$#" -ne 1 ]
then
@whereisaaron
whereisaaron / snippet.cs
Created August 3, 2022 11:35
Route two different AWS ECS/Fargate container ports (80 & 443) via two different Network Load Balancer Target Groups with AWS CDKv2
var myService = new FargateService(this, "MyService", new FargateServiceProps {
Cluster = myCluster,
DesiredCount = 2,
AssignPublicIp = true,
TaskDefinition = myTaskDef,
EnableExecuteCommand = true,
});
targetGroupPort80.AddTarget(new [] {
service.LoadBalancerTarget(new LoadBalancerTargetOptions {
@whereisaaron
whereisaaron / openvpn-simple-password-auth.sh
Created April 10, 2022 08:49
Simple external script to use with OpenVPN or similar for username and password authentication (auth-user-pass-verify)
#!/bin/bash
#
# Read username and password from the supplied filename
#
readarray -t lines < $1
username=${lines[0]}
password=${lines[1]}
#
@whereisaaron
whereisaaron / unzip-recursive.ps1
Created March 27, 2022 07:29
Unzip a tree of folders containing ZIP files, requires PowerShell and 7z
Get-ChildItem –Path "C:\temp" -Recurse |
Where-Object -Property Extension -EQ '.zip' |
Foreach-Object {
Write-Output $_.FullName
$command = "7z x ""$($_.FullName)"" -o""$($_.Directory)"" -aos -bso0 -bsp2"
Write-Output $command
@whereisaaron
whereisaaron / json-to-helm-values.sh
Created September 10, 2020 06:20
Convert JSON object to YAML values for a helm chart
#!/bin/bash
json_to_values() {
json=$1
echo "env:"
jq -r 'to_entries | .[] | " - name: \(.key)\n value: '"'"'\(.value)'"'"'"' <<<$json
}
read -r -d '' foo << END
{