Skip to content

Instantly share code, notes, and snippets.

@erincerys
erincerys / kayako-backups.sh
Created June 23, 2014 21:07
Backup attachment cache and MySQL schema of a Kayako helpdesk deployment to an AWS S3 bucket if there are any changes when compared to the previous backup
#!/bin/bash
storagedir='/root/backups'
backupdir='/var/www/__swift/files'
s3path='live-kayako-caches/backups/'
s3cpath="$(which python) /root/s3cmd-1.5.0-beta1/s3cmd"
if [ ! -d ${storagedir} ] ; then mkdir ${storagedir} ; fi
cd ${storagedir}
curdate=$(date -u '+%Y%m%d')
@erincerys
erincerys / truecrypt-package-verification.sh
Created July 21, 2014 00:21
Download truecrypt 7.1a, verify the SHA256 checksum against an independent and trusted source and install the package
#!/bin/bash
# You might want to change the download url to another if your system is not using the amd64 architecture
wget -c -q https://www.grc.com/misc/truecrypt/truecrypt-7.1a-linux-x64.tar.gz
TC_CHECKSUM=`sha256sum ./truecrypt-7.1a-linux-x64.tar.gz | awk '{print $1}'`
TC_VERIFIED_CHECKSUM=`curl -s https://defuse.ca/downloads/truecrypt-hashes.asc | grep -A19 -i sha256 | grep 'truecrypt-7.1a-linux-x64.tar.gz$' | awk '{print $1}'`
if [ -n "${TC_VERIFIED_CHECKSUM}" ] ; then
if [ "${TC_CHECKSUM}" == "${TC_VERIFIED_CHECKSUM}" ] ; then
tar xfz truecrypt-7.1a-linux-x64.tar.gz
@erincerys
erincerys / inititalize-mysql.sh
Last active August 29, 2015 14:11
An rc.local script tailored for MySQL servers running on AWS EC2 i2.xlarge instances. It will create the partition table on ephemeral storage, format the disk ext4, download a data store from S3, and start the MySQL server.
#!/bin/sh -e
# This is a draft and may not work for you.
# Dependencies:
# - aws python cli toolset
# - qpress / quicklz
# - s3-mutlipart.py
# Search an array for an element
## http://stackoverflow.com/a/8574392/2272443
@erincerys
erincerys / replication_check.sh
Created January 23, 2015 17:41
A shell script to monitor a MySQL replication connection.
#!/bin/bash
# Monitor and report a status code somewhere about a MySQL slave's replication connection
# Useful for when traditional monitoring cannot be achieved due to firewalling.
D=`date -u +"%Y%m%d%H%M"`
mysqlparams='-h... -ureplicator -p...'
query='show slave status\G'
logfile='/var/log/replication_check.log'
@erincerys
erincerys / luks-helper.sh
Last active August 29, 2015 14:14
Shell script helper to close or suspend an open LUKS container
#!/bin/bash
# Description:
# Take action to secure an open LUKS container
# Helpful when bound to a keyboard shortcut in your favorite DE/WM
# DISCLAIMER:
# Must be ran as root - take care in securing access to this script
# I added a selective line to /etc/sudoers.d such as:
# %wheel ALL=(ALL) NOPASSWD: /bin/bash /path/to/script/ close /path/to/mountpoint
@erincerys
erincerys / commands.cfg
Created May 18, 2015 18:54
nagios3 notifier for pushbullet integration
# I've only included the two command additions to the this commands.cfg file
# 'notify-host-by-push' command definition
define command{
command_name notify-host-by-push
command_line /usr/bin/curl --header 'Authorization: Bearer <your_access_token_here>' -X POST https://api.pushbullet.com/v2/pushes --header 'Content-Type: application/json' --data-binary '{"type": "note", "title": "* $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **", "body": "***** Nagios ***** Notification Type: $NOTIFICATIONTYPE$ Host: $HOSTNAME$ State: $HOSTSTATE$ Address: $HOSTADDRESS$ Info: $HOSTOUTPUT$ Date/Time: $LONGDATETIME$", "email": "<email_associated_with@pushbullet-account.here>"}'
}
# 'notify-service-by-push' command definition - ident
define command{
@erincerys
erincerys / backup-ec2.sh
Last active September 27, 2015 02:33
Backup some directories on an EC2 instance to S3 as a tarball, prune old archives and publish result to an SNS topic
#!/bin/bash
# INVOCATION: bash $0
# LOG LOCATION: $storagedir/$prefix-DATESTAMP.log
# NOTES:
# - Install this in your crontab on an appropriate schedule. Filenames are to minute resolution.
# - Depending on the method in which AWS CLI was installed, it may not be in $PATH when cron executes. This will be evident in your local user mail and the script log
# CONFIGS
storagedir="$HOME/backups"
@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 / .s3cfg
Created February 16, 2016 20:52
Script to collect response times and catch errors from an S3-like service - useful to benchmark performance over time
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
@erincerys
erincerys / summate-imdb-list-runtime.sh
Last active February 19, 2016 04:47
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
#!/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