Skip to content

Instantly share code, notes, and snippets.

View akorn's full-sized avatar

Dr. András Korn akorn

  • Budapest, Hungary
View GitHub Profile
akorn / find-interface
Last active February 25, 2022 20:04
A script to be called from `pre-up` in `interfaces(5)`: it examines a set of configured candidate interfaces to find the one that's plugged into the network you want, then renames it to a descriptive name you've chosen. Use case: you have many similar physical interfaces and don't want to keep track of which cable you plug into which.
View find-interface
# Copyright (c) 2019-2022 András Korn. License: GPLv3
# Take a set of network interfaces and determine which one is plugged into a specific network. Then rename the interface.
# This script supplies some generic functions for that purpose; the actual logic comes from configuration (you need to override the detect() function and perhaps the last_resort() function).
# The script is concurrency capable. It processes candidate interfaces simultaneously, obtaining a lock for each; other instances skip locked interfaces and add them to the end of their queue.
# Several instances can run concurrently with overlapping candidate POOLs.
akorn / list-disk-status
Last active February 25, 2022 20:20
Query the status of all local SATA/SAS hard drives and summarize in a table; also for disks on hpsa controllers
View list-disk-status
# Copyright (C) 2016, 2022 András Korn. Licensed under the GPL v3.
# Purpose: query the status of all local SATA hard drives and summarize in a table.
# Not complete, but good enough for my own purposes. Patches welcome.
typeset -A diskattrs
typeset -A diskargs
akorn / runcached
Last active March 23, 2023 16:40
Run specified (presumably expensive) command with specified arguments and cache result. If cache is fresh enough, don't run command again but return cached output.
View runcached
# Purpose: run specified command with specified arguments and cache result. If cache is fresh enough, don't run command again but return cached output.
# Also cache exit status and stderr.
# Copyright (c) 2019-2023 András Korn; License: GPLv3
# Use silly long variable names to avoid clashing with whatever the invoked program might use
akorn / zfs-properties-backup.zsh
Created October 15, 2018 10:46
Script to back up zfs metadata, also in the form of zfs create commands
View zfs-properties-backup.zsh
zfs get all -Hp -s local,received >/var/backups/zfs-properties.txt
zpool get all >/var/backups/zpool-properties.txt
for i in $(zfs list -t filesystem,volume -H -o name); do
unset props
zfs get all -o property,value -Hp -s local,received $i | while read prop value; do
props=($props[@] "-o $prop"="'$value'")
echo zfs create ${(o)props[@]} $i
done >/var/backups/zfs-create-commands.txt
akorn / browser-suspender
Last active May 19, 2020 13:19
A zsh script to automatically suspend browser instances that don't have focus, and unsuspend them when they receive focus. They get to run for a bit every few minutes even if they don't have focus so they can update/display notifications etc.
View browser-suspender
# Idea from
# Copyright (c) 2017-2020 András Korn. License: GPLv3
# Run this from a user-level runsvdir (runit), or from an endless loop, or using systemd, set to restart.
# Make sure you start browsers in their own process group (e.g. `chpst -P browser`). (TODO: maybe support cgroups?)
akorn /
Last active March 12, 2023 21:44 — forked from rcoup/
This script can transfer large directory structures with parallel rsync workers. Example command line: `rsync_parallel . -- -aHSAX --exclude '*13' . /tmp/2/.`
# Copyright (c) 2014, 2020 by Dr. András Korn. Implements the basic idea of a similar script by Robert Coup (2013).
# License: GPLv3
function usage() {
echo 'Usage:
rsync_parallel [--parallel=N] <args to find(1) to generate list of stuff to transfer> -- <args to rsync>