Skip to content

Instantly share code, notes, and snippets.

@brwyatt
brwyatt / ui_stock_check.sh
Last active January 28, 2023 01:05
Ubiquiti Store stock checker
#!/bin/bash
models=(
"switch-enterprise-8-poe"
"usw-enterprise-24-poe"
"usw-enterprise-48-poe"
"usp-rps"
)
do_check () {
@brwyatt
brwyatt / git_puppet_count.sh
Created December 29, 2018 23:29
Script to count the lines of Puppet code for each commit in a Git repo
#!/bin/bash
file="/tmp/count.csv"
echo "datetime,commit,lines" > "${file}"
for i in $(git log --pretty='%ct:%H'); do
d=$(echo "${i}"|cut -f1 -d':')
c=$(echo "${i}"|cut -f2 -d':')
@brwyatt
brwyatt / ssh_proxy.sh
Created June 1, 2017 05:48
Bash script to automatically proxy SSH connections through a proxy host when off-network
#!/bin/bash
# Put the following in the `~/.ssh/config` for each host to
# conditionally proxy:
# ProxyCommand ssh_proxy.sh %h %p bastion.example.net
if [ $# -ne 3 ]; then
echo "USAGE: $0 HOST PORT PROXYHOST" >&2
exit 99
fi
#!/bin/bash
servers=()
unset input
read -p "Server ${#servers[@]}: " input
while [ ${#servers[@]} -eq 0 ] || [[ "x${input}" != "x" ]]; do
if [[ "x${input}" != "x" ]]; then
servers=("${servers[@]}" $input)
fi
unset input
@brwyatt
brwyatt / nukeAllCephOSDs.sh
Created July 11, 2016 03:26
Script to out, stop, and remove all (unencrypted) Ceph OSDs and partitions from a system
#!/bin/bash
osds=($(systemctl list-units | grep -iE 'ceph-osd@[[:digit:]]+\.service' | tr -s ' ' | cut -f2 -d' ' | cut -f2 -d'@' | cut -f1 -d'.'))
for i in "${osds[@]}"; do
echo "***Outing OSD $i"
ceph osd out $i
done
read -p "***Pausing for replication/recovery. Press [ENTER] when done..." $DONE
@brwyatt
brwyatt / findNewestFile.sh
Last active August 23, 2016 17:08
BASH script to find the newest file under a directory structure
#!/bin/bash
if [[ "x${1}" == "x" ]]; then
dir="."
else
dir="${1}"
fi
# Based on https://stackoverflow.com/questions/10575665/linux-find-command-find-10-latest-files-recursively-regardless-of-time-span
# with additions to return only the date of the newest file

Keybase proof

I hereby claim:

  • I am brwyatt on github.
  • I am brwyatt (https://keybase.io/brwyatt) on keybase.
  • I have a public key whose fingerprint is 7139 4C8E CA4A B1BE B85E B202 B83E E2D5 5C50 C6B2

To claim this, I am signing this object:

@brwyatt
brwyatt / aliases.sh
Last active August 29, 2015 14:07
Handy Aliases for BASH
# Update all repositories under ~/repos.
# Works for SVN and GIT (very simplistic)
alias update-repos="ls ~/repos | xargs -I% bash -c 'echo -e \"\e[0;34mUpdating %\e[0m\"; cd ~/repos/% ; if [ -d .svn ]; then svn update; elif [ -d .git ]; then git fetch -v; else echo -e \"\e[0;31mNot a repo\e[0m\"; fi'"
# Calls `svn diff` and adds some color to the output to make changes stand out
alias colordiff="svn diff | sed -E 's/^(@@.*@@)$/\x1b[0;34m\1\x1b[0m/' | sed -E 's/^(Index: .*|=*)$/\x1b[0;33m\1\x1b[0m/' | sed -E 's/^(\+.*)$/\x1b[0;32m\1\x1b[0m/' | sed -E 's/^(\-.*)$/\x1b[0;31m\1\x1b[0m/' | less -R"
@brwyatt
brwyatt / GraphGit.sh
Last active March 17, 2016 09:15
Create a directed graph from a Git repo using dot
#!/usr/bin/env bash
# based on http://chiu01.blogspot.com/2012/04/git-tip-using-graphviz-to-display.html
# Use: ./GraphGit.sh [FromCommitish] [ToCommitish]
echo 'digraph "git" {' > graph.dot
git log --pretty='format: %h [label="%h\n%an <%ae>\n%ai\n%s" shape=box]' $1..$2 | perl -p -e 's/([0-9a-f]{7})/"\1"/' >> graph.dot
git log --pretty='format: %h -> { %p }' $1..$2 | perl -p -e 's/([0-9a-f]{7})/"\1"/g' >> graph.dot
echo '}' >> graph.dot
dot -Tpng graph.dot -o graph.png
@brwyatt
brwyatt / generatePassword.sh
Created April 29, 2014 19:28
Generate a 15-25 character password with lower/upper-case, numbers, -, and _
#!/bin/bash
cat /dev/urandom|tr -dc 'a-zA-Z0-9_-'|fold -w$(echo "($RANDOM%10)+15"|bc)|head -n1