Skip to content

Instantly share code, notes, and snippets.

View starkers's full-sized avatar

David Stark starkers

  • London, UK
  • 10:59 (UTC +01:00)
View GitHub Profile
@starkers
starkers / myip
Created May 17, 2014 16:57
Determine you're outbound (http) IP and reverse DNS
#!/usr/bin/env bash
# Depends on curl and dig
TIMEOUT=1
SERVER=4.2.2.3
IP=`curl -s --connect-timeout "$TIMEOUT" https://outboundip.com 2>/dev/null`
#echo :$?:
@starkers
starkers / any2mp3
Last active August 29, 2015 14:01
Convert any flv/mp4 and pretty much anything into .mp3
#!/usr/bin/env bash
# any2mp3
# Converts to mp3 anything mplayer can play
# requires: mplayer and lame
# Also ensure you have space to dump the .wav
TMP=audiodump-`date +%s`.wav
[ "$1" ] || { echo "Usage: $0 file1.wma file2.mp4"; exit 1; }
@starkers
starkers / doorman
Last active August 29, 2015 14:01
Looping command doorman - I use this "doorman" to comapre output of two slightly different commands
#!/usr/bin/env bash
# This script loops forever and waits for a standard STDIN for each loop.
#
# When you hit [RETURN] it pipes you're input into the command you launched the script with
#
# For example.. If I want to compare public DNS records (on 4.2.2.3 for example) with the
# records on my own DNS server.. EG: 1.2.3.4 I would split a terminator it two and run:
# Terminal 1: doorman dig @4.2.2.3 +short
# Terminal 2: doorman dig @1.2.3.4 +short
@starkers
starkers / gencsr
Last active August 29, 2015 14:01
Generate a webserver csr quickly and easily
#!/usr/bin/env bash
#
# simple templating script for Generating CSR's -david@starkers.org 121001
# .. this relies on having openssl availble in your path ..
# Its not elegant but its easy to use..
#
# TODO: too much ugly wraping of whitespace into openssl commands
# (there is another way but I forgot and this works)
# This program is free software. It comes without any warranty, to
@starkers
starkers / yubiwatch
Last active August 29, 2015 14:13
yubiwatch
#!/usr/bin/env bash
ENV="$(env)"
if ! grep -q DISPLAY= <<<"$ENV" ; then
echo dunno what your DISPLAY= is, setting default and crossing fingers
export DISPLAY=:0
fi
# simple script that watches for a Yubikey being plugged in..
#
@starkers
starkers / wp_backup
Last active August 29, 2015 14:14
wp_backup.sh
#!/usr/bin/env bash
# quickly backs up a wordpress install for you, just specify the wordpress install path
ConfFile="$1/wp-config.php"
if [ "X$1" == "X" ]; then
echo ".. quickly backs up a wordpress database for you, just specify the wordpress install path"
@starkers
starkers / send_file.sh
Created May 21, 2015 19:06
rar a file up, password protect it, then email it as an attachment with mailx
#!/usr/bin/env bash
## This rar's a file up with a password and emails it
## not as good as using openssl to encrypt but I'm not about to explain openssl pipes to my users
# rar does the job :/
FILE=/var/log/some_logfile.log
PASS="your super top secret password"
@starkers
starkers / grants.sh
Last active August 29, 2015 14:23
dump mysql grants into SQL compatible sytax
#!/usr/bin/env bash
set -o nounset # Treat unset variables as an error
#
# you can call this script as such if needed:
# ./grants --user="mymysqlusername" --pass="password" --host="somehost"
#
# I much prefer .my.cnf or similar
@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
#!/usr/bin/env bash
#who gets alerted
DEST=your@email.com
#from address
FROM="noreply@server.example.org"
#directory to monitor
DIR=/www