Skip to content

Instantly share code, notes, and snippets.

@erincerys
erincerys / atlassian2s3.sh
Created September 26, 2013 16:45
Schedules a backup of an Atlassian OnDemand instance and uploads the resulting file to S3
#!/bin/bash
#
# Obtained from:
# https://confluence.atlassian.com/display/ONDEMANDKB/Automatic+backups+for+JIRA+OnDemand
# and modified to include:
# - longer waiting period for backup to be created
# - S3 upload
#
@erincerys
erincerys / mysql2cassandra.py
Created March 26, 2014 17:20
Dumps a MySQL table and reformulates it into JSON to be ingested into a Cassandra table
#! /usr/bin/env python
#
# mysql2cassandra.py
# Dump a MySQL result set to file and then import into a Cassandra column family
#
# Configuration
# mysql_params [host, port, user, password, db] MySQL conenction parameters
# mysql_columns [colname, colname2, ...] Columns for building MySQL query
# The column that will hold values of the row key in the Cassandra column family must be first
@erincerys
erincerys / dumper.pl
Last active August 10, 2016 14:56 — forked from shantanuo/dumper.pl
MySQLdump filter -- Removes or replaces the DEFINER clauses from a dump
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long qw(:config no_ignore_case );
my $replace = undef;
my $delete = undef;
my $help = 0;
GetOptions (
@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
@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 / spinhours.sh
Last active December 30, 2015 07:59
Return your drives' power on hours via smartctl (requires smartmontools)
#!/bin/bash
if [ ! "$(which smartctl)" ] ; then
echo "smartmontools is not installed"
exit 1
fi
logical=($(df | grep -Eo 'sd[a-z]'))
# This doesn't preserve the mountpoint of the raid device, but whatevs for now
@erincerys
erincerys / deduplicate-column.sql
Last active December 27, 2015 15:09
If you require adding a UNIQUE key to a MySQL table, but the desired column contains duplicates, this stored procedure will assist in raising cardinality by appending random numbers to the end of a duplicate record.
DELIMITER $$
CREATE PROCEDURE `sp_utility_deduplicate_column` (IN table_in VARCHAR(64), IN unique_in VARCHAR(64), IN nonunique_in VARCHAR(64), length_in INT(11))
BEGIN
/* sp_utility_deduplicate_column
IN table_in The name of the table to execute deduplication on
IN unique_in The PRIMARY KEY for table_in (auto-incremented integer recommended)
IN nonunique_in The column that contains duplicated values (INDEX recommended)
@erincerys
erincerys / fscheck.sh
Last active December 26, 2015 14:29
Shutdown a server if a fusefs connection become unreliable
#!/bin/bash
# If a fusefs connection has been lost, shutdown the server and optionally log the event to an S3 object.
# I use this AWS EC2 instances in auto-scaling groups. If it shuts down, it gets terminated by the ASG, and replaced with a fresh one.
# Might be some fringe cases in the error handling code that haven't been encountered or thought of. Hence, might not be 100% reliable, so use at your own risk
cd /root
# Create lock
lockfile='/root/fscheck.lock'
@erincerys
erincerys / mysql2file.py
Created September 26, 2013 16:59
Execute mysql query and write to file utilizing a streaming cursor
#! /usr/bin/env python
from sys import argv
import csv
import MySQLdb
from MySQLdb import cursors
mysql_params = [argv[1], argv[2], argv[3], argv[4], argv[5]]
output_file = argv[6]
mysql_query = argv[7]
@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{