Skip to content

Instantly share code, notes, and snippets.

View mortn's full-sized avatar

Morten Abildgaard mortn

View GitHub Profile
@mortn
mortn / dhcp-leases-changed.py
Created June 12, 2014 21:32
pyinotify example for watching DHCP leases file
import pyinotify,subprocess
def onChange(ev):
cmd = ['/bin/echo', 'File', ev.pathname, 'changed']
subprocess.Popen(cmd).communicate()
wm = pyinotify.WatchManager()
wm.add_watch('/var/lib/dhcp/dhcpd.leases', pyinotify.IN_MODIFY, onChange)
notifier = pyinotify.Notifier(wm)
notifier.loop()
#!/bin/bash
function main()
{
monitor_from_file $*
}
function monitor_vpn_ip_port()
{
local CONN_NAME=$1
@mortn
mortn / vlan.sh
Last active August 29, 2015 14:09
Expect script for vlan tagging on 4 HP Procurve (Really have to find a better way)
#!/usr/bin/env expect
set CTRLZ \032
set action [lindex $argv 0]
set vlan [lindex $argv 1]
if {[llength $vlan] == 0} { exit 0; }
if {$vlan < 3000} { exit 0; }
if {$vlan > 9100} { exit 0; }
stty -echo
send_user -- "Gimme Passwordz: "
expect_user -re "(.*)\n"
#!/usr/bin/env python
#Copyright (C) 2009 Allen Sanabria
#This program is free software; you can redistribute it and/or modify it under
#the terms of the GNU General Public License as published by the Free Software Foundation;
#either version 2 of the License, or (at your option) any later version.
#This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
#without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#See the GNU General Public License for more details. You should have received a copy of i
@mortn
mortn / djablo.sh
Last active August 29, 2015 14:10
Method for starting a Mezzanine/Django site via Upstart script on Ubuntu 14.04
#!/bin/bash
set -e
NUM_WORKERS=3
USER=www-data
GROUP=users
DIR=$(dirname $0)
APPNAME=${DIR##*/}
LOGFILE=/var/log/gunicorn/$APPNAME.log
LOGDIR=$(dirname $LOGFILE)
cd $DIR
@mortn
mortn / formula-setup.sh
Created July 8, 2015 19:23
Saltstack formula setup script for easy setup
#!/bin/bash
formulas="django dnsmasq haproxy nginx ntp owncloud php postfix users varnish vim"
formula_root=/srv/formula
states_root=/srv/salt
pillars_root=/srv/pillar
[ ! -d $formula_root ] && mkdir $formula_root
cd $formula_root
for f in $formulas;do
ff=$f-formula
if [ ! -d $formula_root/$ff ]; then
@mortn
mortn / ldap_users.py
Created July 13, 2015 22:36
Python LDAP
#!/usr/bin/python2
# -*- coding: utf-8 -*-
import sys
import ldap
from credz import ldap as _c
## You can just set the variables on the next 4 lines directly
## - or you can create your own credential handler
base_dn = _c.base_dn # CN=users,DC=domain,dc=example,dc=com
ldap_user = _c.username # user@domain.example.com
@mortn
mortn / hosts-upd8r.sh
Last active September 21, 2015 14:02
Dynamically update hosts file from PTR/reverse lookup
#! /bin/bash
set -e
[ "x" == "x$(dig +short @10.0.0.1 -x 10.0.0.1)" ] && exit 0
header="### This file is generated by $0 ###
127.0.0.1 localhost
127.0.1.1 $(hostname)"
footer="# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
@mortn
mortn / ringtone.sh
Last active September 29, 2015 14:33
Getting a Android ringtone from audio track from a Youtube vid...
#!/bin/bash
### Linux FTW! Because this is how you get a ringtone for you mobile/cell phone
### I did this is on a Ubuntu 15.04
VID=[YOUTUBE_VIDEO_ID]
# Get the video and extract the audio on the fly
# sudo apt-get -y install youtube-dl
youtube-dl -o '%(id)s.%(ext)s' -x --audio-format best https://www.youtube.com/watch?v=$VID
# Cut the beginning of the audio track so it starts from 4 seconds in and continues for 31 secs.
# At the same time convert the audio track from AAC to OGG (my Android phone loves that for ringtones)
@mortn
mortn / hitch-tls-build.sh
Last active October 1, 2015 22:15
Compiling hitch on Ubuntu 15.04
sudo apt-get -y install libssl-dev libev-dev clang autoconf automake
git clone https://github.com/varnish/hitch.git
cd hitch
export CC=clang
./bootstrap
./configure --prefix=/usr
make -j4
cd src/tests && runtests && cd ../..
sudo cp hitch.conf.ex /etc/hitch.conf