Skip to content

Instantly share code, notes, and snippets.

View zushane's full-sized avatar

Shane Doucette zushane

View GitHub Profile
@zushane
zushane / pre-commit
Last active April 15, 2019 21:39
A git pre-commit hook to run phpunit tests, written in bash. Features pretty colours, and slightly individualized output.
#!/bin/bash
# Locate our phpunit.
phpunit=`which phpunit`
# Any extra arguments to phpunit should go here.
phpunit_args=""
# Define a location to save the output.
outputlog="/tmp/phpunit_output_`date +%s`.log"
@zushane
zushane / MySQL Table Size
Last active August 29, 2015 13:55
A short MySQL snippet to display table sizes of the mentioned DATABASE_NAME in a fine tabular format.
SELECT table_name, engine, table_rows, data_length, ROUND(((data_length+index_length)/1024/1024),0) "MB"
FROM information_schema.tables
WHERE table_schema = 'DATABASE_NAME'
ORDER BY data_length;
@zushane
zushane / s3backup.sh
Last active August 29, 2015 13:57
A short script to backup the S3 buckets on an account, to a local directory.
#!/bin/bash
###
# A short script to sync S3 to a local directory.
# Read arguments
while getopts ":c:b:dts" opt ; do
case $opt in
c)
if [ -e ${OPTARG} ] ; then
@zushane
zushane / httpdmonitor
Last active August 29, 2015 13:58
monitor httpd via tcpdump
# tcpdump filter for HTTP GET
sudo tcpdump -s 0 -A 'tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x47455420'
# tcpdump filter for HTTP POST
sudo tcpdump -s 0 -A 'tcp dst port 80 and (tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x504f5354)'
@zushane
zushane / apachestrace.sh
Created April 9, 2014 22:04
Trace system calls for all current and future apache processes.
ps auxw | grep sbin/apache | awk '{print"-p " $2}' | xargs strace -f
@zushane
zushane / apsc.sh
Created May 29, 2014 17:29
Apache Process Size Check - check total memory usage of all Apache httpd processes.
#!/bin/bash
ps -ylC httpd | awk '{x += $8;y += 1} END {print "Apache Memory Usage (MB): "x/1024; print "Average Proccess Size (MB): "x/((y-1)*1024)}'
@zushane
zushane / mailtest.sh
Last active August 29, 2015 14:15
Simple mail test script.
#!/bin/bash
server=`hostname`
timestamp=`date +%s`
mail_subject="${1-"$timestamp"} ($server)"
mail_address=${2-"test@example.com"}
mail_message="/tmp/$timestamp.message"
mail_program="/bin/mail"
echo "Sending test mail to $mail_address, with subject \"$mail_subject\""
@zushane
zushane / xvfb.service
Created October 20, 2015 19:09
systemd Xvfb startup configuration
# Copy this file to /etc/systemd/system/xvfb.service
# Then execute:
# systemctl enable /etc/systemd/system/xvfb.service
# systemctl start xvfb.service
[Unit]
Description=X Virtual Frame Buffer Service
After=network.target
[Service]
@zushane
zushane / reboot_airports.applescript
Last active November 17, 2015 16:51
A simple script to do unattentded reboot of Airport devices. It assumes that all of the devices are sequential, with none to skip. Works best on a server.
--
-- Simple script to do unattented reboot of Airport devices.
-- Assumptions: all the devices are sequential, with none to skip.
--
-- only run this script if it's before 5am.
set foo to do shell script "date +%H"
set thisHour to foo as number
if thisHour < 5 then
#!/bin/bash
if [[ $# -ne 1 ]]; then
echo "Usage: $(basename $0) user"
exit 99
fi
HOST=ldap.example.com
BASE_DN="dc=example,dc=com"
ROOT_DN="cn=admin,${BASE_DN}"