Skip to content

Instantly share code, notes, and snippets.

@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 ; }
@erincerys
erincerys / xmr-mining-scheduler.sh
Last active October 11, 2017 21:41
Schedule CPU utilization of your cryptocurrency miner around your personal computer use patterns
#!/bin/bash
#
# usage: $0 <cpu-threads>
#
# i use this script to schedule times of day when my computer is not in use can max out cpu on the miner
#
# example cron entries:
# 00 06 * * * /path/to/xmr-mining-scheduler.sh 3
# 00 23 * * * /path/to/xmr-mining-scheduler.sh 4
@erincerys
erincerys / .bash_aliases
Last active August 27, 2017 18:39
Bash configuration
# maintenance
alias sysupgrade='yaourt -S -y -u --aur'
# operations
function gpkill () {
if [ $1 ] ; then
TargetPid=`pgrep $1`
echo 'Sending sigterm'
kill -15 $TargetPid
sleep 2
@erincerys
erincerys / pwrstatd-lowbatt.sh
Created August 20, 2017 23:29
CyberPower PowerPanel configuration set to gracefully attempt to dismount drives before signalling shutdown in event of UPS low battery
#!/bin/sh
echo "Warning: The UPS's battery power is not enough, system will be shutdown soon!" | wall
export RECEIPT_NAME
export RECEIPT_ADDRESS
export SENDER_ADDRESS
#
# If you want to receive event notification by e-mail, you must change 'ENABLE_EMAIL' item to 'yes'.
# Note: After change 'ENABLE_EMAIL' item, you must asign 'RECEIPT_NAME', 'RECEIPT_ADDRESS', and