Skip to content

Instantly share code, notes, and snippets.

@hflamboauto1
hflamboauto1 / mysqlslavecheck.sh
Created July 6, 2016 11:01 — forked from magnetikonline/mysqlslavecheck.sh
Example bash script for a PRTG SSH script sensor - this one for MySQL slave to master checks.
#!/bin/bash
# query MySQL for slave replication status
# note: requires [~/.my.cnf] to be present a populated with valid MySQL password
mysql \
-u root \
-Be "SHOW GLOBAL STATUS LIKE 'Slave_running'" | \
tail -n1 | grep -Pqe "^Slave_running\tON$"
if [ $? -eq 0 ]; then
@hflamboauto1
hflamboauto1 / README.md
Created July 6, 2016 11:02 — forked from magnetikonline/README.md
Bash if conditions with functions().

Bash if conditions with functions()

Some examples of calling bash functions in if; then; fi conditionals - both functions that echo and return.

#!/bin/bash

function functionOne {

	echo -n "$1 - $2"
}
@hflamboauto1
hflamboauto1 / README.md
Created July 6, 2016 11:03 — forked from magnetikonline/README.md
AWS CLI S3 usage examples.
@hflamboauto1
hflamboauto1 / README.md
Created July 6, 2016 11:03 — forked from magnetikonline/README.md
Transfer MySQL databases between AWS RDS instances.

Transfer MySQL databases between AWS RDS instances

The situation

  • Two AWS RDS MySQL databases - moving databases from source to destination.
  • Both databases are not publicly accessible, only via an EC2 instance(s) - e.g. you have setup your security groups.
  • Can SSH to a target EC2 instance (but of course).

What it does

  • Sets up two SSH port forwards on local machine - one to the source database, another to target.
  • Via calls to transferDatabase():
@hflamboauto1
hflamboauto1 / README.md
Created July 6, 2016 11:03 — forked from magnetikonline/README.md
SSH forward local port to remote AWS RDS MySQL instance.

SSH forward local port to remote AWS RDS instance

The scenario:

  • Connectivity to remote server (e.g. EC2 instance) over SSH.
  • Connectivity to AWS RDS MySQL instance from remote server only (due to security group/firewall settings).
# forward requests from 127.0.0.1:6400 -> RDS.ENDPOINT.rds.amazonaws.com:3306
# add [-f] switch to background ssh process
$ ssh -vvvN \
	-L 6400:RDS.ENDPOINT.rds.amazonaws.com:3306 \
@hflamboauto1
hflamboauto1 / example.sh
Created July 6, 2016 11:04 — forked from magnetikonline/example.sh
AWS EC2 extract IAM role data from HTTP instance data using bash & curl.
#!/bin/bash
IAM_BASE_URL="http://169.254.169.254/latest/meta-data/iam/security-credentials"
IAMRoleName=$(curl -s $IAM_BASE_URL/)
IAMRoleData=$(curl -s $IAM_BASE_URL/$IAMRoleName/)
IAMRoleAccessKeyID=$(echo -n "$IAMRoleData" | sed -nr 's/.*?"AccessKeyId"[^"]+"([^"]+)",?/\1/p')
IAMRoleAccessKeySecret=$(echo -n "$IAMRoleData" | sed -nr 's/.*?"SecretAccessKey"[^"]+"([^"]+)",?/\1/p')
IAMRoleToken=$(echo -n "$IAMRoleData" | sed -nr 's/.*?"Token"[^"]+"([^"]+)",?/\1/p')
@hflamboauto1
hflamboauto1 / README.md
Created July 6, 2016 11:05 — forked from magnetikonline/README.md
AWS RDS MySQL parameter group tweaks.

AWS RDS MySQL parameter group tweaks

Parameter Value AWS default
character_set_server utf8
collation_server utf8_general_ci
default_storage_engine InnoDB InnoDB
innodb_buffer_pool_size {DBInstanceClassMemory*7/10} {DBInstanceClassMemory*3/4}
innodb_log_file_size 134217728 134217728
max_allowed_packet 4194304
@hflamboauto1
hflamboauto1 / README.md
Created July 6, 2016 11:05 — forked from magnetikonline/README.md
Create id_rsa public/private keys from supplied PPK formatted key file.

Create id_rsa public/private keys from supplied PPK formatted key file

Instructions for Ubuntu 14.04LTS (and more than likely others). Where keyfile.ppk is the PPK file you have in hand.

$ sudo apt-get install putty-tools
# create public key as [id_rsa.pub]
$ puttygen keyfile.ppk -o id_rsa.pub -O public-openssh
# create private key as [id_rsa]
$ puttygen keyfile.ppk -o id_rsa -O private-openssh
@hflamboauto1
hflamboauto1 / README.md
Created July 6, 2016 11:06 — forked from magnetikonline/README.md
Using Dnsmasq with Ubuntu 16.04LTS/14.04LTS/12.04LTS for virtual machine web application testing.

Using Dnsmasq with Ubuntu for VM web application testing

When running virtual machines under a Linux host system for testing web apps in various browsers (e.g. Internet Explorer), I found it rather tedious having to continually tweak the hosts file within each VM for the purpose of adding entries pointing back to the host machine's development web server address.

Instead the steps below will setup Dnsmasq on a Ubuntu 16.04LTS, 14.04LTS or 12.04LTS host machine for the purpose of serving both it's own DNS queries and that of virtual machine guests. Dnsmasq will parse the /etc/hosts file on your host machine where we will keep a single set of DNS entires to our test web application(s).

@hflamboauto1
hflamboauto1 / autoscaling_boto.py
Created July 6, 2016 11:09 — forked from numan/autoscaling_boto.py
Example of setting up AWS auto scaling using boto API
"""
The MIT License (MIT)
Copyright (c) 2011 Numan Sachwani
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions: