Skip to content

Instantly share code, notes, and snippets.

@wkettler
wkettler / carbon-cache
Last active December 25, 2015 14:59 — forked from chalmerj/gist:1492384
#!/bin/bash
#
# carbon-cache
#
# Graphite's carbon-cache daemon init script.
#
# William Kettler <william.p.kettler@gmail.com>
#
# Source init-functions
#!/bin/bash
####################################
# Last tested & updated 04/09/2014
####################################
VERS="0.9.12"
# Make sure only root can run script
if [[ $EUID -ne 0 ]]
then
@wkettler
wkettler / zstatus.sh
Last active December 30, 2015 18:29
zstatus.sh checks the status of each zpool on the system and will send an email if all pools are not healthy. The check can be automated by adding the script to crontab.
#
# zstatus.sh
#
# Check pool status.
#
EMAIL="test@somewhere.com"
HOSTNAME="$(hostname)"
# Linux
STATUS="$(/sbin/zpool status -x)"
#!/bin/bash
#
# makemkv.sh
#
# Rip a DVD/BLURAY using MakeMKV.
#
DIR="/srv/media/dvdimport/backup/"
LOG="/tmp/makemkv.log"
DRV=0
def prompt_yn(question):
"""
Prompt the user with a yes or no question.
Input:
question (str): Question string
Output:
answer (bool): Answer True/False
"""
while True:
@wkettler
wkettler / execute.py
Last active November 3, 2023 06:29
Python subprocess with timeout.
import subprocess
import signal
class Signal(Exception):
"""
This exception is raise by the signal handler.
"""
pass
import re
def to_bytes(value):
"""
Convert a size string with an exponent into bytes.
Input:
value (str): Size string
Output:
bytes (int): Size in bytes
import re
def to_units(value, unit):
"""
Convert a size string from unit x to unit y.
Input:
value (str): Size string
unit (str): Unit to convert to
Output:
def prompt(question, answers):
"""
Prompt the user with a question and only accept defined answers.
Input:
question (str): Question string
answers (list): A list containing accpeted response value
Output:
answer (str|int): Provided answer
"""
@wkettler
wkettler / get_zpool_drives.py
Last active August 29, 2015 13:56
Return the device ID's for all drives in a zpool.
from execute import execute, Retcode
import re
def get_zpool_drives(zpool):
"""
Returns all drives in the zpool.
Inputs:
zpool (str): Zpool name
Outputs: