Skip to content

Instantly share code, notes, and snippets.

@dncrews
Last active December 20, 2015 14:09
Show Gist options
  • Save dncrews/6144285 to your computer and use it in GitHub Desktop.
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)
#!/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
@nicjohnson
Copy link

Added output verbiage and made the commands "live" by default: https://gist.github.com/nicjohnson/6186293

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment