Skip to content

Instantly share code, notes, and snippets.

View dale-c-anderson's full-sized avatar

Dale Anderson dale-c-anderson

View GitHub Profile
@dale-c-anderson
dale-c-anderson / where-is-it-hosted.sh
Created January 19, 2016 22:46
Does some lookups to help find out where a machine or domain is hosted, given a dns name or IP address.
#!/bin/bash
# Show some help
if (( $# != 1 )); then
echo ""
echo "Usage: $(basename $0) <domain.com>"
echo "Does some lookups to help find out where a website is hosted, given a domain name."
echo ""
exit 1
@dale-c-anderson
dale-c-anderson / hook-chain-install.sh
Last active June 14, 2016 11:41
Git Hook Chaining
#!/bin/bash -ue
# To use:
# wget -q -O - https://gist.githubusercontent.com/dale-c-anderson/b791c79de07d604b76db/raw/hook-chain-install.sh | bash
# @TODO: Allow use of either wget or curl (try the other if the first doesn't exist)
function main () {
DIRNAME=$(basename "$PWD")
@dale-c-anderson
dale-c-anderson / backdir
Created April 5, 2016 19:50
Quickly tar up a folder
#!/bin/bash
##############################################
# File: backdir
# Author: Dale C. Anderson
# Purpose: Small script to quickly back up a folder
##############################################
set -u # Fail if an undeclared variable is used (helps when making changes / debugging)
@dale-c-anderson
dale-c-anderson / postgrey_restart.sh
Created August 8, 2016 05:06
Postgrey restart script is broken on Ubuntu, and has been forever. What year is it again??
#!/bin/bash -u
# Restart postfix on Ubuntu 14.04
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
service postgrey status
@dale-c-anderson
dale-c-anderson / strip-comments.sh
Created August 16, 2016 16:15
Strips comments from config files. Can be used with filename arguments, or with pipes.
#!/bin/bash
function main () {
if [ $# -gt 0 ]; then
# Someone sent us a filename
cat "$@" | grep -v ^\; | grep -v ^$ | grep -v ^\ $ | grep -v '^#'
else
if [ -t 0 ]; then
# Someone called us without args or pipes.
usage
@dale-c-anderson
dale-c-anderson / make-fake-swap-file.sh
Last active August 29, 2020 01:30
Create an ad-hoc swap file for AWS nano / micro servers
#!/bin/bash -ue
####################
# For small AWS EC2 instances that have no swap space by default.
# A tiny, slow swap file may be preferable to having the server's OOM killer shutting down processes.
# A real swap on ephemeral storage is better, but this will do in a pinch.
# The disadvantage is that if a server starts using swap, it will burn through it's EBS disk burst credits very quickly.
# Works on Ubuntu 14,16,18, LTS. Not tested on any other platform.
####################
@dale-c-anderson
dale-c-anderson / apache-wordpress.conf
Created October 13, 2016 00:13
Quick and dirty fail2ban filter for blocking obnoxious shitheads who attempt bad things on your wordpress site
# /etc/fail2ban/filter.d/apache-wordpress.conf
#
# Fail2Ban configuration file
#
# Author:
# Dale Anderson <danderson@acromediainc.com>
#
# Description:
# Bans anyone who tries to POST to a PHP file (existing or not) in the wp-content/uploads directory.
#
@dale-c-anderson
dale-c-anderson / nginx-drupal-wordpress-secure.conf
Created October 28, 2016 08:09
Secure Wordpress + Drupal virtual host configuration for NGINX
server {
listen 80;
server_name www.example.com;
access_log /var/log/vhosts/myaccount/myproject/nginx-access.log;
error_log /var/log/vhosts/myaccount/myproject/nginx-error.log;
root /var/vhosts/myaccount/www/myproject/wwwroot;
index index.html index.php;
client_max_body_size 8m;
#!/bin/bash
W_PATH="$(xclip -selection clipboard -o)"
U_PATH="$(echo "$W_PATH" | sed -e 's/\\/\//g' -e 's/A:/\/media\/accounts/g')"
nautilus "$U_PATH"
@dale-c-anderson
dale-c-anderson / ubuntu-remove-php55.yml
Created February 24, 2017 18:44
ansible php 5.5 removal from ubuntu 14.04
---
- hosts: all
gather_facts: true
become: yes
tasks:
- name: Remove php5-fpm
apt: name=php5-fpm
update_cache=no