Skip to content

Instantly share code, notes, and snippets.

View johnl's full-sized avatar

John Leach johnl

View GitHub Profile
@johnl
johnl / set-all-file-mtime-to-commit-time.sh
Last active January 13, 2023 16:56
Change file modification timestamps to the last git commit timestamps for all files in a git tree
#!/bin/bash
git ls-files -z | xargs -0 -n1 -I{} -- git log -1 --format="%at {}" {} | perl -ane '($t,$f)=@F;utime($t,$t,$f)'
@johnl
johnl / nginx-status.nse
Last active February 27, 2021 13:39
nmap script to check if a service is serving an nginx status page
local http = require "http"
local nmap = require "nmap"
local shortport = require "shortport"
local string = require "string"
description = [[
Detects if the service is serving an nginx status page
]]
---
@johnl
johnl / collectd.conf
Created November 20, 2020 23:08
collectd script to report ipt hashtable sizes
<Plugin exec>
Exec "nobody" "/usr/local/bin/collectd_ipt_hashtable.sh"
</Plugin>
@johnl
johnl / terraform wrapper
Last active August 4, 2020 09:50
a script to run the right version of terraform for the current repository
#!/bin/bash
# this script expects to find each terraform version binary available in the path
# with the filename format terraform_0.x.x
#
# requires jq
# doesn't currently support reading states in terraform workspaces
function die {
echo $1
exit 1
@johnl
johnl / cowstat.rb
Created November 27, 2012 19:49
Display info about ram shared between Linux processes
#!/usr/bin/env ruby
require 'ostruct'
class LinuxProcess < OpenStruct
def initialize(args)
super
read_status!
end
@johnl
johnl / broadcast.rb
Created August 17, 2018 15:32
Puppet Facter v2+v3 compatible broadcast address fact provider. Get broadcast address for each available network interface.
# Fact: broadcast
#
# Purpose:
# Get broadcast addresses for each interface.
#
Facter.value('interfaces').split(',').each do |interface|
Facter.add("broadcast_" + interface) do
setcode do
require 'ipaddr'
@johnl
johnl / powerdns.conf
Created June 8, 2012 17:29
xip.io implementation with powerdns_pipe in ruby
launch=pipe
pipe-command=/path/to/xipio-pipe.rb
pipe-timeout=200
pipe-regex=^.*.ip.ipq.co;.*$
@johnl
johnl / scsi-log-parser.rb
Created May 13, 2015 15:30
script to parse Linux scsi command logs
#!/usr/bin/ruby
# Parses linux scsi command logs
# http://www.seagate.com/staticfiles/support/disc/manuals/scsi/100293068a.pdf
# give this program itself as input to test
# DE AD BE EF == 3735928559
# CA FE == 51966
# CDB: Write(10): 2a 08 DE AD BE EF 00 CA FE 00
@johnl
johnl / gnome-keyring-key-deleter.py
Created February 15, 2018 14:43
rough and dangerous script to delete all keys in gnome-keyring matching a certain application id
#!/usr/bin/env python
import getpass, re, sys
import gnomekeyring
all_items = gnomekeyring.list_item_ids_sync("login")
for item in all_items:
attributes = gnomekeyring.item_get_attributes_sync("login", item)
if attributes.has_key("application") == False or attributes["application"] != "chrome-10788085": continue
print attributes["action_url"]
@johnl
johnl / segfault-shared-lib-symbol-resolver.rb
Created January 5, 2018 18:50
Script to resolve segfault symbol addresses in shared libs
#!/usr/bin/ruby
# use this like: dmesg | grep segfault | segfault-shared-lib-symbol-resolver.rb | addr2line -e /usr/lib/debug/usr/lib/i386-linux-gnu/libruby-2.1.so.2.1.0
# kernel: [352246.560406] ruby[1178]: segfault at bf6630d0 ip b75f6fa3 sp bf6630c0 error 6 in libruby-2.1.so.2.1.0[b7469000+254000]
STDIN.each_line do |l|
r = /ip ([^ ]+).*\[([^+]+)/
m = r.match l
ip = m[1].to_i(16)
offs = m[2].to_i(16)