Skip to content

Instantly share code, notes, and snippets.

@john-auld
john-auld / detect linux OS
Created March 5, 2019 11:18
Identify Linux OS
#!/bin/bash
detect_os (){
# Check the OS version
if [ -f /etc/os-release ]; then
source /etc/os-release
else
# Most likely a Centos5/6 box
if [ -f /etc/redhat-release ]; then
if grep -iq centos "/etc/redhat-release"; then
@john-auld
john-auld / aws-ec2-nat-example.md
Created March 6, 2019 11:54
Example of using an EC2 instance to proxy LDAPS on an AWS managed Domain Controller
EIP <--> (EC2 Instance) <--> (AWS AD DC with ldaps enabled)
cat ldaps_iptables
#!/bin/sh

sysctl -w net.ipv4.ip_forward=1

Json Path pattern

$..groups[?(@.name)].name

json body

{"groups":
  [
    {"name": "g1"},
    {"name": "g2"}
 ]
@john-auld
john-auld / openresty-lua-dump-headers.md
Created March 28, 2019 14:16
nxinx-lua dump request headers

Basic example of lua code to dump request headers

This code will dump the request headers into the response body of an nginx location. It is intended for degugging development and not for production. The code has been tested on OpenResty.

nginx location

location /status {
 default_type text/html;
@john-auld
john-auld / rotate_aws_keys.py
Last active July 27, 2019 15:57
Python 3 compatible script to rotate aws access keys
'''
Rotate AWS access keys for each profile in the users ${HOME}/.aws/credentials file.
Note: the default profile is not altered
Author: John Auld
'''
import configparser
import os
import boto3
@john-auld
john-auld / s3_delete_bucket.py
Created April 3, 2019 12:22
Delete S3 bucket containing versions
'''
Delete a bucket that contains versions.
Author: John Auld
'''
import boto3
my_bucket = 'replace-with-aws-s3-bucket-name'
delete_bucket = False
delete_versions = False
@john-auld
john-auld / git-commands.md
Last active April 16, 2019 12:52
Useful git commands

check if local branch is up to date

git remote show origin

tidy up local branches that have been deleted from the origin

git fetch --prune

@john-auld
john-auld / screen.md
Created April 16, 2019 15:42
Linux screen command

Create named screen

screen -S screen-name

Detach screen

Ctrl+a d

List screens

screen -ls

Attach screen

@john-auld
john-auld / netcat-udp-connectivity-test.md
Last active April 17, 2019 09:50
UDP Connectivity check

No connectivity

nc -u -z -w 3 8.8.8.8 54 && echo OK || echo failed
failed

With connectivity

nc -u -z -w 3 8.8.8.8 53 && echo OK || echo failed
OK