Skip to content

Instantly share code, notes, and snippets.

@erincerys
erincerys / kill-locks.sh
Last active October 6, 2025 12:08
Kill processes holding locks on a given file path by progressively issuing higher severity signals for each PID.
#!/bin/bash
# shellcheck disable=SC2086
#
# DESCRIPTION:
# 'safely' kill processes holding file locks for a file path
# useful for managing mountpoints with user session state changes
#
# USAGE:
# $0 <file-path>
@erincerys
erincerys / safe-kill.sh
Created October 5, 2025 13:58
Issues progressively more severe kill signals to one or more PIDs
#!/bin/bash
test -z "$1" && exit 1
declare -a _PGREP; _PGREP+=('pgrep')
test ${#1} > 15 && _PGREP+=('--full')
_PGREP+=('--ignore-ancestors' "$1")
mapfile -t _PIDS < <("${_PGREP[@]}")
test ${#_PIDS[@]} = 0 && exit 1
_SIGNALS=(15 1 3 6 9)
@erincerys
erincerys / git-pull-recursively.sh
Created October 5, 2025 13:55
Recursively traverses directories to update Git repositories from remote
#!/bin/bash
#
# DESCRIPTION:
# iterates through a directory and its subdirectories
# updating any git repositories from remote
#
set +e
for d in *; do
@erincerys
erincerys / migration-irssi-logs.sh
Created August 8, 2017 04:05
Merge irssi log directories, deleting small files
#!/bin/bash
# migrate.sh
# DESCRIPTION: Parse two directories of logfiles.
# FUNCTION: Append new files with old ones, delete files that are small, and move new files that aren't present to the old directory.
# USAGE: bash migrate.sh /path/to/old_logdir /path/to/new_logdir
# ELABORATION:
# Settings
minlines=15 # Threshhold number of lines to delete a logfile
@erincerys
erincerys / create-memtest-usb.sh
Created December 21, 2015 00:39
Prepare a USB flash drive with syslinux and memtest86+ for RAM testing
#!/bin/bash
# Install dependencies for creating filesystem and installing bootloader
## This script is mostly system-independent, except for this part. Replace yaourt and the args with your own package manager
yaourt -S --noconfirm mtools syslinux dosfstools
# Plug in the flash drive, and find its device. Don't mount it.
lsblk
while [[ $(echo $FLASHDEV | grep -c \/dev\/sd[a-z]) -lt 1 && -b "$FLASHDEV" ]] ; do
read -p 'Which device (e.g. /dev/sdf)? ' FLASHDEV
@erincerys
erincerys / restic-b2-cronjob.sh
Last active February 2, 2020 16:15
Backup given sources via restic to B2 at regularity using SNS to notify of result
#!/bin/bash
# Requires:
# - restic (system package)
# - AWS account with SNS topic configured and API keys created
# - awscli (pip) with API keys configured (aws configure)
# - Backblaze B2 account with API keys
# - cron implementation (system package)
ResticBinaryPath=`which restic`
@erincerys
erincerys / s3-b2-cronjob.sh
Created February 2, 2020 16:13
Backup given sources via restic to AWS S3 at regularity using AWS SNS to notify of result
#!/bin/bash
# Requires:
# - restic (system package)
# - AWS account with SNS topic configured, S3 bucket created, and API keys created
# - awscli (pip) with API keys configured (aws configure)
# - cron implementation (system package)
ResticBinaryPath=`which restic`
AwsCliBinaryPath=`which aws`
@erincerys
erincerys / rds2redshift.sh
Last active January 27, 2020 15:38
Loads a MySQL data dump into a Redshift table. Useful for AWS RDS instances. Dependent on external script to stream MySQL data to file, and postgres psql command line client.
PYTHON_PATH=$(which python)
PSQL_PATH=$(which psql)
MYSQL_SCRIPT='mysql2file.py'
MYSQL_SERVER=
MYSQL_PORT=3306
MYSQL_DATABASE=
MYSQL_USER=
MYSQL_PASSWORD=
@erincerys
erincerys / personal-backup.sh
Last active January 13, 2019 04:23
Backup directories and directory listings to a LUKS container and sync everything to S3
#!/bin/bash
## Description:
# Sync files to and create lists of directory contents in a LUKS container volume and upload it to S3
# Good for periodic backup jobs
# Supports rate limiting, encryption in transit and at rest and file path exclusions
## Usage:
# bash $0
@erincerys
erincerys / check-systemd-service.sh
Last active January 19, 2018 19:37
Script to be remotely invoked by nagios that returns a service's status and can trigger an alarm when down or failed
#!/bin/bash
## Checks a systemd controlled service for status and start failures
SVC_NAME='servicename'
COUNT_FILE='/tmp/checkservice.counter'
# load counter from previous checks
[ -f $COUNT_FILE ] && { COUNT=`cat $COUNT_FILE` ; } || { COUNT=0 ; }