Skip to content

Instantly share code, notes, and snippets.

@wkettler
wkettler / dd.py
Last active July 21, 2023 08:01
A Python wrapper for the GNU dd command.
from execute import execute, Retcode
def dd(ifile, ofile, bs, count=None, seek=None):
"""
Wrapper for the GNU dd command.
Inputs:
ifile (str): Input file
ofile (str): Output file
bs (str): Block size
@wkettler
wkettler / ipcheck.sh
Last active August 29, 2015 13:57
Track public IP and notify by email if it has changed.
#!/bin/bash
#
# ipcheck.sh
#
# Check public IP and notify by email if it has changed.
#
EMAIL="test@test.com"
LOG="/root/.myip"
@wkettler
wkettler / parse_table.py
Last active August 29, 2015 13:58
Parse a text based table such as those frequently returned when executing commands via bash.
def parse_table(f, idx=0, delim=None, head=None):
"""
Parse a table.
Inputs:
f (str): Path to file
idx (int): Index column
delim (str): Table delimiter
head (list): Optionally defined table header
Outputs:
@wkettler
wkettler / pprint_table.py
Last active August 29, 2015 14:06
Pretty print a list of list, i.e. a table.
def pprint_table(table):
"""
Pretty print table.
Inputs:
table (list): table
Outputs:
None
"""
padding = []
#!/bin/bash
#
# hddcheck.sh
#
# Modified version of http://www.cyberciti.biz/files/scripts/monitor-my-hard-disk.sh.txt.
#
# Generate a warning email based on hard drive temps.
#
TO=test@test.com
@wkettler
wkettler / tree.py
Last active August 29, 2015 14:11
Autovivification removes need for horrendous nested calls to {}.setdefault() when working with trees in python. my_tree = tree() my_tree['tra']['la']['la']
from collections import defaultdict
def tree():
return defaultdict(tree)
#!/usr/bin/env bash
#
# Install/update MakeMKV.
#
TMP=$(mktemp -d)
# Get current version
VERS=$(curl --silent "http://www.makemkv.com/download/" 2>&1 | \
egrep -o 'MakeMKV ([^ ]*) for' | \
@wkettler
wkettler / s3share
Last active September 6, 2017 03:16
Upload a file to S3 and return a signed URL.
#!/usr/bin/env python
"""
Upload a file to S3 and return a signed URL.
William Kettler <william.p.kettler@gmail.com>
"""
import sys
import os
import subprocess
#!/bin/bash
TIMESTAMP=$(date +"%F")
BACKUP_DIR="/backup/$TIMESTAMP"
MYSQL=/usr/bin/mysql
MYSQLDUMP=/usr/bin/mysqldump
NTFY=/usr/local/bin/ntfy
mkdir -p "$BACKUP_DIR/mysql"
#!/bin/bash
if [ "$PAM_TYPE" == "close_session" ]; then
exit
fi
curl -s -X POST -H 'Content-type: application/json' SLACK_WEBHOOK \
-d @- > /dev/null << EOF
{
"attachments": [