Skip to content

Instantly share code, notes, and snippets.

View starkers's full-sized avatar

David Stark starkers

  • London, UK
  • 12:52 (UTC +01:00)
View GitHub Profile
@starkers
starkers / redis_purge.py
Created June 6, 2016 15:25
iterate over redis and delete keys
#!/usr/bin/env python
from optparse import OptionParser
import redis
def main():
parser = OptionParser()
parser.add_option("-d", "--database", default=0, help="target redis database, default is 0", dest="database")
parser.add_option("-a", "--address", default="127.0.0.1", help="target redis host, default is 127.0.0.1")
parser.add_option("-p", "--port", default=6379, help="target redis host, default is 127.0.0.1")
@starkers
starkers / iptables.generic
Last active May 25, 2016 16:09
Simple iptables
cat > /tmp/iptables.generic <<EOF
*filter
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:LOGGING - [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -d 127.0.0.0/8 ! -i lo -j REJECT --reject-with icmp-port-unreachable
-A INPUT -p tcp -m tcp ! --tcp-flags FIN,SYN,RST,ACK SYN -m state --state NEW -j DROP
@starkers
starkers / youtubehelper
Last active May 20, 2016 11:46
simple youtube downloader, crude cleanup and tagging
#!/usr/bin/env bash
##This is very crude.. but its enough for me [meh]
# contents of this text file is a youtube URL per line.. EG:
#--
#cat listofvideos.txt
#https://www.youtube.com/watch?v=RrLAaDCPc3I
#--
fileVideoList=listofvideos.txt
@starkers
starkers / directory_size_watch.sh
Created May 13, 2016 15:13
simple monitoring of a directorys size, no rocket science
#!/usr/bin/env bash
# DESC: simple monitoring of directory growth.. does a du and informs you the diff on a loop
# defaults to 300 second loop
# USAGE: this_script.sh "/some/directory/to/watch" is the directory to watch
# sample output:
#Fri May 13 13:12:06 BST 2016: thing grew by 132
#Fri May 13 13:17:07 BST 2016: thing grew by 83
#Fri May 13 13:37:07 BST 2016: thing shunk by 1575
#Fri May 13 13:42:07 BST 2016: thing grew by 596
@starkers
starkers / no caps
Created January 15, 2016 11:56
converting trash in a spreadsheet
#!/usr/bin/env bash
convert_to_lower (){
IN="$1"
tr '[:upper:]' '[:lower:]' <<< "$IN"
}
clipboard_output(){
#graps clipboard and prints to stdout
@starkers
starkers / simple_mysql_backup.sh
Last active November 20, 2015 11:44
Very crude, very simple mysql dumps.. relies on ~/.my.cnf grants allowing full access to dump/lock etc..
#!/usr/bin/env bash
PATH=$PATH:/usr/bin/
# how to long to keep backups for (in days)
KEEP=150
# Where to keep them
BACKUP_PATH="/root/mysql_backups/sql"
host="localhost"
@starkers
starkers / firewall
Created October 2, 2015 15:39
A reasonably secure iptables stack to port forward to containers and isolate internal LANs
#!/usr/bin/env bash
# I use this on servers hosting multiple containers.
# It lets me reasonably easily manage ports without typing too much
# Works on openvz and lxc... nothing really magical
# Beware the spoof detection ranges.. if you expect legit traffic from one of these networks the modify it
# There are a few bugs but generally this works well.. YMMV -david
#public IP on my host (eth0)
IP1=178.62.XX.XX
@starkers
starkers / lxc-prep
Last active February 17, 2020 17:08
Install SSH keys into lxc containers
#!/usr/bin/env bash
if [ "X$1" == X ]; then
echo "prepares a new container does the following:"
echo "- installs ssh keys from $KEYS"
echo "- sets random root passwords"
echo "- deletes the 'ubuntu' user"
echo
echo "usage: 'lxc-prep <container_name>'"
echo
#!/usr/bin/env bash
#who gets alerted
DEST=your@email.com
#from address
FROM="noreply@server.example.org"
#directory to monitor
DIR=/www
@starkers
starkers / clear_web_logs.sh
Created June 26, 2015 11:45
randomly staggered crontask
#!/usr/bin/env bash
# This script allows me to run a crontab at a random point in the next hour.
# WHY?
# Using something like a little delay can also stop ALL the servers hammering a proxy at once for example.
# ...or if something breaks I don't take the entire cluster down at once
# Do the task at some random point within the next X minutes:
X=60