Skip to content

Instantly share code, notes, and snippets.

View JCotton1123's full-sized avatar

Jesse Cotton JCotton1123

View GitHub Profile
@JCotton1123
JCotton1123 / add-ga.sh
Last active December 24, 2015 05:09
Add Google analytics snippet to files with the ability to filter on file extension and mime type
#!/bin/bash
# This is the snippet that will be added to each file
includeGAString="<!--#include virtual=\"/includes/ga.inc\" -->"
#includeGAString="<script>
# (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
# (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
# m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
# })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
#
@JCotton1123
JCotton1123 / bench.sh
Created September 30, 2013 02:09
Apache Bench script - needs some work
#!/usr/local/bin/bash
numberOfRequestsValues="10 20 40"
concurrencyValues="1 2 4"
abCmd="/usr/local/sbin/ab"
for url in $(cat $1); do
echo "# $url"
echo
@JCotton1123
JCotton1123 / parse-slow-log.sh
Last active May 5, 2023 13:13
Parse php-fpm slow log
## Slow requests grouped by function call
cat /var/log/php-fpm/www-slow.log | grep -A 1 script_filename | \
grep -v script_filename | grep -v -e "--" | cut -c 22- | sort | uniq -c | sort -nr
## Slow requests grouped by minute
cat /var/log/php-fpm/www-slow.log | grep 'pool www' | \
cut -d' ' -f2 | sort | cut -d: -f1,2 | uniq -c
## Top 25 1 minute groups of slow requests
cat /var/log/php-fpm/www-slow.log | grep 'pool www' | cut -d' ' -f2 | \
@JCotton1123
JCotton1123 / apache-vhost-report.php
Last active December 28, 2015 15:19
Apache Vhost Report
#!/usr/bin/php
<?php
$directory = $argv[1];
$output_column_headings = array(
"Config File",
"Virtual Host",
"ServerName",
"DocumentRoot",
@JCotton1123
JCotton1123 / postfix-sasl-auth.sh
Created November 21, 2013 07:20
Postfix relay SASL authentication
#!/bin/sh
cd /etc/postfix
sed -i 's/#relayhost = \[an.ip.add.ress\]/relayhost = [smtp.mailgun.org]:587/g' main.cf
echo >> main.cf
echo "smtp_sasl_auth_enable = yes" >> main.cf
echo "smtp_sasl_password_maps = static:USERNAME:PASSWORD" >> main.cf
echo "smtp_sasl_security_options = noanonymous" >> main.cf
echo >> main.cf
/etc/init.d/postfix restart
@JCotton1123
JCotton1123 / gist:7759674
Last active December 30, 2015 01:59
Linux CLI snippets
## All IPs
egrep -o "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
## Find a distinct list of file exts within a specified directory
find ./ -type f -name "*.*" -exec basename {} \; | rev | cut -d. -f 1 | sort | uniq | rev
## Find files with the supplied exts (linux)
find ./ -regextype posix-extended -regex ".*(mp3|mp4|pdf|PDF|doc|zip|ZIP|wav|gz)$"
## Find files with supplied exts (mac)
#!/usr/bin/env ruby
require 'rubygems'
require 'net/http'
require 'uri'
require 'json'
require 'pry'
class User
attr_accessor :login
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite
@JCotton1123
JCotton1123 / apache-log-to-delim.py
Created July 15, 2014 19:04
Parse an apache log into a pipe-delimited file
from __future__ import print_function
import sys
import re
parts = [
r'(?P<host>\S+)', # host %h
r'\S+', # indent %l (unused)
r'(?P<user>\S+)', # user %u
r'\[(?P<time>.+)\]', # time %t
r'"(?P<request>.+)"', # request "%r"
@JCotton1123
JCotton1123 / parse-mac-trap.sh
Created August 17, 2014 07:03
Parse snmp mac notification trap
#!/bin/sh
LOG_FILE=/var/log/snmp/mactrap.log
read host
read ip
ip=`echo $ip | cut -d"[" -f2 | cut -d"]" -f1`
while read oid value