Skip to content

Instantly share code, notes, and snippets.

View zushane's full-sized avatar

Shane Doucette zushane

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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"