Skip to content

Instantly share code, notes, and snippets.

View forestbaker's full-sized avatar

input - process - output forestbaker

View GitHub Profile
# ==[ printSlack ]=============================================================
# Function to send output from the commandline to Slack.
#
# @parameter string $LEVEL INFO/ERROR/WARNING message. Changes emoji
# @parameter string $MESSAGE Message to send to slack.
printSlack()
{
SLACK_HOSTNAME=${SLACK_HOSTNAME-'oops.slack.com'};
SLACK_TOKEN=${SLACK_TOKEN-'oops'};
SLACK_CHANNEL=${SLACK_CHANNEL-'#devops'};
@forestbaker
forestbaker / kvdiff
Created October 11, 2015 22:03 — forked from nemasu/kvdiff
Bash function that compares files containing key-value pairs.
#$1,2 = files containing x=y style key-values
#sort, awk, grep friendly
#Duplicate keys are not handled
function kvdiff() {
tmpfile=`mktemp`
OLD_IFS=$IFS;
IFS=$'\n'
declare -A left;
declare -A right;
@forestbaker
forestbaker / Notes
Created October 11, 2015 21:59 — forked from slank/Notes
Bash Power Tips Walkthrough
# Variables
FOO=here
FOO="here" # equivalent, always use quotes
BAR=$FOO
BAR="$FOO"
BAR="${FOO}"
BAR='$FOO' # single quotes, does not evaluate the variable
@forestbaker
forestbaker / send_text_with_data
Created October 11, 2015 21:45 — forked from vladkosinov/send_text_with_data
Send message in telegram from bash script
#!/bin/bash
if [ $# -lt 2 ]; then
echo "Usage: send.bash USER_NAME MESSAGE [DATA ... DATA]"
exit 1
fi
USER=$1
MESSAGE=$2
if [ $# -ge 3 ]; then
@forestbaker
forestbaker / mysql_db_sync
Created October 11, 2015 21:42 — forked from vasiliishvakin/mysql_db_sync
Simple bash script to sync remote mysql db to local
#!/bin/bash
LOCAL_DB=""
REMOTE_DB=""
LOCAL_USER="root"
LOCAL_PASS=""
REMOTE_USER="root"
REMOTE_PASS=''
@forestbaker
forestbaker / bandit24-solution
Created October 11, 2015 21:39 — forked from vinzdef/bandit24-solution
4 digit pin bruteforce using Bash expansions for Over The Wire bandit25
for x in {0..9}{0..9}{0..9}{0..9}; do
echo UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ $x | nc localhost 30002 | egrep -v "Exiting|Wrong|I am";
echo "Try $x";
done
@forestbaker
forestbaker / upgrade_starcluster.sh
Created October 11, 2015 21:34 — forked from nickjacob/upgrade_starcluster.sh
script to safely upgrade starcluster & dependencies
#!/usr/bin/env bash
# upgrade starcluster
####
mute_run ()
{
$* >/dev/null 2>&1
}
cecho ()
{
@forestbaker
forestbaker / pre-commit.sh
Last active November 16, 2015 04:16 — forked from nickjacob/pre-commit.sh
Pre-commit hook to check for extra-large files that you probably shouldn't have in version control
#!/usr/bin/env bash
echo '================================================================================'
echo 'PRE-COMMIT: CHECKING FILE SIZES'
echo '================================================================================'
# constant that you want to check sizes against
SIZE_LIMIT=$(( 1048576 * 64 ))
# $1 - filetype
#!/bin/bash
# generate a number of files with random sizes in a range
min=1 # min size (MB)
max=10 # max size (MB)
nofiles=20 # number of files
for i in `eval echo {1..$nofiles}`
do
dd bs=1M count=$(($RANDOM%max + $min)) if=/dev/urandom of=./files/file$i
_
_._ _..._ .-', _.._(`))
'-. ` ' /-._.-' ',/
) \ '.
/ _ _ | \
| a a / |
\ .-. ;
'-('' ).-' ,' ;
'-; | .'
\ \ /