Skip to content

Instantly share code, notes, and snippets.

View jiphex's full-sized avatar

James Hannah jiphex

View GitHub Profile
@jiphex
jiphex / countdir.pl
Created October 27, 2011 10:23
Count files in a (LARGE) directory
#!/usr/bin/perl
if (!defined($ARGV[0]) or ! -d $ARGV[0]) {
print "Supply a valid path\n";
}
opendir(THEDIR,$ARGV[0]);
my $counter = 0;
while (my $file = readdir(THEDIR)) {
$counter++;
}
closedir(THEDIR);
@jiphex
jiphex / filesystem.py
Created October 24, 2011 11:37
Python Filesystem Class
class Filesystem(object):
# Represents a Filesystem, with convenience methods to generate the mount command
BLANK=0x0
FAT16=0x4
NTFS=0x7
EXT=0x83
LVM=0x8e
FAT32=0xb
SWAP=0x82
VMFS=0xfb
@jiphex
jiphex / propagatestuff.sh
Created October 3, 2011 10:19
Propagate Things by Shell/rsync
#!/bin/sh
#
# SERVICES is a space-separated list of services to reload
# FILES is a list of configuration files to propagate from localhost to $HOSTS
# HOSTS is a list of servers to propagate things to.
#
# Assumes that some kind of passwordless SSH is already setup.
RELOADSERVICES=""
RESTARTSERVICES="varnish"
@jiphex
jiphex / locktest.c
Created September 2, 2011 12:09
Lock Testing Program
// JH Lock Test - 20110902
// I've used this in the past to debug locking issues (NFS)
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
char * filename;
@jiphex
jiphex / generate-rfc4193-addr.sh
Created August 26, 2011 10:32
Generate RFC4193 Shell Script
#!/bin/sh
#
# @(#) generate-rfc4193-addr.sh (ULA) (c) Sep 2004 - Jun 2011 Holger Zuleger
#
# do what the name suggest
#
# firstpart = 64-Bit NTP time
# secondpart = EUI-64 Identifier or 48 Bit MAC-Adress
# sha1sum ($firstpart | $secondpart )
# use least significant 40 Bits of sha1sum
@jiphex
jiphex / backup_mysql.sh
Created August 3, 2011 09:23
Remote MySQLdump backup with Rsync driver
#! /bin/bash
# script to backup MySQL data to remote server
# James Hannah - January 2009
# set some variables
FILENAME="`date +mysqldump-%Y-%m-%d-%H:%M:%S`.sql"
LOCALFILE="/home/sql_backup/$FILENAME"
LOCKFILE="/tmp/sqlbackup.lock"
BACKUPSERVER="10.1.1.1"
MYSQLPASS="secretsgohere"
@jiphex
jiphex / distributionreport.py
Created June 30, 2011 11:24
LogCat - python tool for debugging [with] syslog.
# Tool for debugging syslog problems, prints logs to stdout with ansi colours
# This version summarises the way that cookies are distributed between incoming servers/backends
import socket
import re
import time
tstart = time.time()
host='localhost'
port=514
@jiphex
jiphex / rsyncd.sh
Last active September 25, 2015 02:57
!/bin/sh
# Rsync driver script
# James Hannah <james at tlyk dot eu>
# PID file name
PIDFILE=/var/run/rsyncd-thing.pid
# check that its not already running
if [ -f $PIDFILE ]; then
OLDPID=`cat $PIDFILE`
@jiphex
jiphex / scanmatic.sh
Created January 16, 2011 23:42
Scans a document from the default scanner and emails it (securely) via GMail
#! /usr/bin/env bash
# scans a single document and mails it
#
# Requirements: sane, ImageMagick, tesseract, gocr, sendemail
# It would be trivially email to remove gocr, tesseract is better it seems
# You could replace ImageMagick with anything that convert PBM > something.
SCANFILE=`mktemp /tmp/scantmp.XXXXXXXX`
PBMFILE="${SCANFILE}.pbm"
#! /usr/bin/env python
#
# Goes through an mbox (filename given in argv[1]) and
# purges messages older than thirty days.
# (and newer than year 3000 to pick up corrupt headers)
#
import sys
import platform
try:
pv = platform.python_version_tuple()