Skip to content

Instantly share code, notes, and snippets.

@mttjohnson
mttjohnson / ansible_version_switch.sh
Last active April 17, 2020 04:46
Ansible Version Switch
Ansible version switch
# For Ansible 2.6.5
brew uninstall ansible
ls /usr/local/Cellar/openssl
# switch to openssl version displayed by /usr/local/Cellar/openssl
brew switch openssl 1.0.2r
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/4dc294072201ea7fe97f9477b9b87f57994af4d3/Formula/ansible.rb
# For Latest (2.9) Ansible Version
@mttjohnson
mttjohnson / mysql_query_analysis.sh
Created January 31, 2020 20:45
MySQL Query Analysis
# Preston referenced:
# https://www.percona.com/doc/percona-toolkit/LATEST/pt-query-digest.html
pt-query-digest slow.log
@mttjohnson
mttjohnson / bash_xml_edit.sh
Created November 7, 2019 20:41
Scripted XML Editing using XSLT and Xpath Expressions (xmllint xsltproc)
# Requirements
# yum install libxml2 libxslt
set +H # disable history expansion
XML_CONTENT=$(cat <<'XML_CONTENT_HD'
<?xml version="1.0" encoding="UTF-8"?>
<confluence-configuration>
<setupStep>complete</setupStep>
@mttjohnson
mttjohnson / automated_ftp_commands
Last active October 1, 2019 20:21
Automating FTP Commands
HOST="127.0.0.1"
USER="username"
PASSWD="password_transmitted_in_cleartext_via_ftp"
TIMESTAMP_UTF=$(date -u +"%Y%m%dT%H%M%SZ")
TIMESTAMP=$(date +"%Y%m%dT%H%M%SZ")
FILENAME="${TIMESTAMP}-${TIMESTAMP_UTF}.temp"
# Create empty temp file with timestamps in filename
@mttjohnson
mttjohnson / gist:d648b2285d5d88cbe5742b373618dcbd
Last active November 12, 2019 15:48
Troubleshooting Yum Repos
# https://unix.stackexchange.com/questions/222750/sudo-yum-repolist-show-repo-not-in-etc-yum-repo-d
yum repolist
yum repoinfo ius
# Repos are either defined via .repo files in /etc/yum.repos.d or via plugins, which are usually defined via files in /etc/yum/pluginconf.d
ls -la /etc/yum.repos.d
ls -la /etc/yum/pluginconf.d
# If you run yum repolist --noplugins does your repo in question still show up?
@mttjohnson
mttjohnson / testing_aws_rds_mysql_multi-az_failover.sh
Created August 30, 2019 21:25
Testing AWS RDS MySQL Multi-AZ Failover Scenario
# https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_RebootInstance.html
# Running mysql commands from app server on private network
DATABASE_NAME="my_database_name"
mysql -D ${DATABASE_NAME} -e '
CREATE TABLE test_inserts (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
client_timestamp varchar(255) DEFAULT NULL,
@mttjohnson
mttjohnson / archive_large_files_splitting_archive.sh
Created August 30, 2019 16:59
Archive large files and splitting archive into chunks
#221G
#/var/www/prod/shared/media/catalog/product
cd /var/www/prod/
tar -zcvf - ./shared/media/catalog/product/* \
| split --bytes=10GB - ~/prod_shared_media_catalog_product.tar.gz.split-
# This creates a list of files
# -rw-rw-r--. 1 www-prod www-prod 10000000000 Aug 29 13:32 prod_shared_media_catalog_product.tar.gz.split-aa
# -rw-rw-r--. 1 www-prod www-prod 10000000000 Aug 29 13:40 prod_shared_media_catalog_product.tar.gz.split-ab
# -rw-rw-r--. 1 www-prod www-prod 10000000000 Aug 29 13:48 prod_shared_media_catalog_product.tar.gz.split-ac
@mttjohnson
mttjohnson / nginx_multi-conditional.conf
Created August 20, 2019 16:14
Nginx multi-conditional for whitelist of IP or user agent at a specific path
# Set the $unauthorized_admin_ip flag if remote_addr is not on list of authorized IPs
map $remote_addr $unauthorized_admin_ip {
# All IPs are considered unauthorized by default
default 1;
"127.0.0.1" 0;
}
map $request_uri $unauthorized_admin_path {
# All paths are considered unauthorized by default and require some other
# means of authorization in order for the request to be accepted.
@mttjohnson
mttjohnson / scripted_ps_kill_matching_pattern.sh
Created August 16, 2019 21:05
Find and kill off old release processes after new release
# Run on the web server to see if any matching processes
# are running outside of the current release directory.
# This does not kill off any processes, just views them.
CUR_REL_PATH="/var/www/html/current"
PROCESS_MATCH="[b]in/magento"
PROCESS_MATCH="
[b]in/magento queue:consumers:start exportProcessor\|
[b]in/magento queue:consumers:start product_action_attribute.update\|
[b]in/magento queue:consumers:start product_action_attribute.website.update\|
[b]in/magento queue:consumers:start codegeneratorProcessor
@mttjohnson
mttjohnson / github_ssh_keys.sh
Last active September 20, 2021 21:59
ssh keys from github user via api
# You can list a user's public ssh keys by going to an address
# https://github.com/mttjohnson.keys
GITHUB_USER="mttjohnson"
curl https://github.com/${GITHUB_USER}.keys
# It is suggested that instead of just curling that end point that it would be better to use the API in any automated fashion
# https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user
curl https://api.github.com/users/mttjohnson/keys