Skip to content

Instantly share code, notes, and snippets.

@erincerys
erincerys / s3-b2-cronjob.sh
Created Feb 2, 2020
Backup given sources via restic to AWS S3 at regularity using AWS SNS to notify of result
View s3-b2-cronjob.sh
#!/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 / restic-b2-cronjob.sh
Last active Feb 2, 2020
Backup given sources via restic to B2 at regularity using SNS to notify of result
View restic-b2-cronjob.sh
#!/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 / check-systemd-service.sh
Last active Jan 19, 2018
Script to be remotely invoked by nagios that returns a service's status and can trigger an alarm when down or failed
View check-systemd-service.sh
#!/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 / .bash_aliases
Last active Aug 27, 2017
Bash configuration
View .bash_aliases
# 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 / xmr-mining-scheduler.sh
Last active Oct 11, 2017
Schedule CPU utilization of your cryptocurrency miner around your personal computer use patterns
View xmr-mining-scheduler.sh
#!/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 / pwrstatd-lowbatt.sh
Created Aug 20, 2017
CyberPower PowerPanel configuration set to gracefully attempt to dismount drives before signalling shutdown in event of UPS low battery
View pwrstatd-lowbatt.sh
#!/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
@erincerys
erincerys / migration-irssi-logs.sh
Created Aug 8, 2017
Merge irssi log directories, deleting small files
View migration-irssi-logs.sh
#!/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 / personal-backup.sh
Last active Jan 13, 2019
Backup directories and directory listings to a LUKS container and sync everything to S3
View personal-backup.sh
#!/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 / summate-imdb-list-runtime.sh
Last active Feb 19, 2016
Simple bash script to get the summed run time of all titles on an imdb.com user list with help of the oMDB API and some open source software
View summate-imdb-list-runtime.sh
#!/bin/bash
# Dependencies (you must have these already installed on your system)
# - jq, JSON processor written in C
# - bc, arbitrary precision numer processor
# - curl, for transferring data given an URL
if [ -z $1 ] ; then
echo 'Pass an argument of the imdb.com list ID i.e. ls123456789 found in the URL'
exit 1
@erincerys
erincerys / .s3cfg
Created Feb 16, 2016
Script to collect response times and catch errors from an S3-like service - useful to benchmark performance over time
View .s3cfg
access_key =
secret_key =
check_ssl_certificate = False
cloudfront_host = IP_OR_FQDN:80
host_base = s3.cloudian.com:18080
host_bucket = %(bucket)s.FQDN:80
# host_bucket = IP:80/%(bucket)s
signature_v2 = False
simpledb_host = IP_OR_FQDN:80