Skip to content

Instantly share code, notes, and snippets.

View DavidGoodwin's full-sized avatar
🐮

David Goodwin DavidGoodwin

🐮
View GitHub Profile
@DavidGoodwin
DavidGoodwin / pressure.sh
Last active February 3, 2022 09:47
linux psi pressure munin plugin
#!/bin/bash
# -*- sh -*-
: << =cut
=head1 NAME
Munin plugin to plot Linux CPU pressure - see: https://lwn.net/Articles/759781/
=head1 CONFIGURATION
@DavidGoodwin
DavidGoodwin / kill-long-running-mysql-queries-in-rds.sh
Created October 9, 2018 19:33
Kill long running MySQL queries (in AWS RDS)
#!/bin/bash
MYSQL="mysql --defaults-extra-file=/path/to/something.cnf"
# Find queries which have been running for longer than 1800 seconds.
for PID in $($MYSQL -BNe "SELECT id FROM information_schema.processlist WHERE command <> 'Sleep' AND info NOT LIKE '%PROCESSLIST%' AND command <> 'Killed' AND time > 1800" )
do
#OUTPUT=$($MYSQL -NBe "SELECT id,time,command,info FROM information_schema.processlist WHERE id = $PID ")
#echo "Long running query output - $OUTPUT "
@DavidGoodwin
DavidGoodwin / tplink.sh
Created January 18, 2018 16:11
control a tplink HS100/HS110 smart plug from bash/the cli
@DavidGoodwin
DavidGoodwin / mysql-backup.sh
Created November 5, 2017 20:37
MySQL backup script (bash)
#!/bin/bash
# Simple backup script for MySQL/MariaDB on a Debian/Ubuntu based server.
# You can run this as often as you like (hourly, daily, weekly). It contains locking to stop multiple executions at once.
# Dependencies:
# apt-get install lockfile-progs
## Begin config.
@DavidGoodwin
DavidGoodwin / lxc_cpu_top.py
Last active April 9, 2017 22:08 — forked from wryfi/lxc_load.py
simple python script to check cpu utilization of lxc containers and print percentage
#!/usr/bin/python
# See https://gist.github.com/wryfi/3902757
# Crude CPU usage thing for container(s).
import multiprocessing, os, re, sys, time
import getopt
cgroup_dir = '/sys/fs/cgroup/lxc/'
SELECT table_schema,
table_name,
data_type,
( CASE data_type
WHEN 'tinyint' THEN 255
WHEN 'smallint' THEN 65535
WHEN 'mediumint' THEN 16777215
WHEN 'int' THEN 4294967295
WHEN 'bigint' THEN 18446744073709551615
end >> IF(Locate('unsigned', column_type) > 0, 0, 1) ) AS MAX_VALUE,
<?php
/*
INSTRUCTIONS: Use at your own risk. Backup your database before continuing.
1. Copy code to a file in the root of your website.
2. Change YOUR_SITE_ROOT to a value that makes sense.
3. Execute by visiting the page. Verify before/after results.
4. Change MAKE_CHANGES_TO_SITE to true and execute it again.
*/
<?php
/*
INSTRUCTIONS:
Use at your own risk. Backup your database before continuing.
1. Copy code to a file in the root of your website.
2. Change YOUR_SITE_ROOT to a value that makes sense.
3. Execute by visiting the page. Verify before/after results.
4. Change MAKE_CHANGES_TO_SITE to true and execute it again.
<?php
/* Original effort: https://gist.github.com/Daniel15/5991193 */
function last($arr)
{
eval('list(' . str_repeat(',', count($arr) - 1) . '$result) = $arr;');
return $result;
}
@DavidGoodwin
DavidGoodwin / sshfp-tinydns.pl
Created March 14, 2014 12:26
convert BIND style SSHFP record into something TinyDNS can understand
#!/usr/bin/perl
use strict;
# Take in, e.g. :
# foobar.palepurple.co.uk IN SSHFP 1 1 9676BB7A92C7E11B90E9508A343A4CAE9888B43D";
# foobar.palepurple.co.uk IN SSHFP 2 1 D4F49CE2195A0BF531275B889ED6ABFF2F24C2BC
# on standard input, and output the appropriate tinydns records for sshfp -
# e.g.
# :foobar.palepurple.co.uk:44:\001\001\226\166\273\172\222\307\341\033\220\351\120\212\064\072\114\256\230\210\264\075:
# :foobar.palepurple.co.uk:44:\002\001\324\364\234\342\031\132\013\365\061\047\133\210\236\326\253\377\057\044\302\274: