Last active
December 20, 2015 14:09
-
-
Save dncrews/6144285 to your computer and use it in GitHub Desktop.
Quick script if you want to add (or remove) a drain from all of your Heroku apps (or those matching a specific prefix)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
while getopts "arp:d:" opt; do | |
case $opt in | |
a) | |
adding=true | |
;; | |
r) | |
adding=false | |
;; | |
p) | |
prefix=$OPTARG | |
;; | |
d) | |
drain=$OPTARG | |
;; | |
\?) | |
echo "Unknown option -$OPTARG" | |
exit 1; | |
;; | |
:) | |
echo "Option -$OPTARG requires an argument" | |
exit 1; | |
esac | |
done | |
if [ -z $adding ] ; then | |
echo "usage (-a or -r) -d 'drainurl' [OPTIONAL: -p 'App_prefix']" | |
exit 1 | |
fi | |
if [ -z $drain ] ; then | |
echo "You haven't defined a drain" | |
exit 1 | |
fi | |
if [ -z $prefix ] ; then | |
read -r -p "Are you sure you have no app prefix? [y/N] " response | |
case $response in | |
[yY][eE][sS]|[yY]) | |
;; | |
*) | |
echo 'Please try again' | |
exit 1; | |
;; | |
esac | |
fi | |
function processDrain { | |
if [[ $adding == true ]] ; then | |
addDrain $1 | |
else | |
removeDrain $1 | |
fi | |
} | |
function addDrain { | |
echo "heroku drains:add ${drain} -a ${1}"; | |
} | |
function removeDrain { | |
echo "heroku drains:remove ${drain} -a ${1}"; | |
} | |
for app in `heroku apps | grep -v =`; do | |
if [[ $app =~ "@" ]] ; then | |
true | |
elif [[ -z $prefix ]] ; then | |
processDrain $app | |
elif [[ $app =~ $prefix ]] ; then | |
processDrain $app | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added output verbiage and made the commands "live" by default: https://gist.github.com/nicjohnson/6186293