Skip to content

Instantly share code, notes, and snippets.

@sveesible
sveesible / validate_ip.sh
Created May 3, 2016 21:59
Validate IP Address from user input in Bash
#!/bin/bash
read -p "What is your IP address?" my_ip
read valid <<< $( awk -v ip="$my_ip" '
BEGIN { n=split(ip, i,"."); e = 0;
if (6 < length(ip) && length(ip) < 16 && n == 4 && i[4] > 0 && i[1] > 0){
for(z in i){if (i[z] !~ /[0-9]{1,3}/ || i[z] > 256){e=1;break;}}
} else { e=1; } print(e);}')
if [ $valid == 0 ]; then
@sveesible
sveesible / parse_yaml_to_vars.sh
Last active June 12, 2020 20:34
Shell script to parse specific field's values from a given yaml file and register them as shell variables with the same field name
#!/bin/bash
## Based on https://gist.github.com/pkuczynski/8665367
## derived from:
## https://gist.github.com/epiloque/8cf512c6d64641bde388
## https://gist.github.com/DinoChiesa/3e3c3866b51290f31243
YAML_FILE=test.yaml
debug=1
function parse_yaml_values() {
@sveesible
sveesible / xtrabackup_runner.sh
Last active December 28, 2020 22:06
A fancier mysql backup script for Xtrabackup:
#!/bin/bash
#
# Script to create full and incremental backups (for all databases on server) using innobackupex from Percona.
# http://www.percona.com/doc/percona-xtrabackup/innobackupex/innobackupex_script.html
#
# Every time it runs will generate an incremental backup except for the first time (full backup).
# FULLBACKUPLIFE variable will define your full backups schedule.
#
# 2012 Brad Svee modified to try to use xbstream
# (C)2012 Atha Kouroussis @ Vurbia Technologies International Inc.
@sveesible
sveesible / pxc_setup.sh
Created September 9, 2015 15:24
A script that attempts to create and configure a percona-xtradb-cluster setup
#!/bin/bash
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Sveesible - PXC-SS - Percona-Xtradb-Cluster-Simple-Setup-Example
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# [Brad Svee] - [07-17-2014] - [PXC-SS] - [1.0]
# ---------------------------------
# [A setup script to help configure a Percona XtraDB MySQL Cluster and Galera]
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
install_percona=true