Last active
July 24, 2017 16:05
-
-
Save joshbeckman/e52a343a667f3660c9495854cba63a6a to your computer and use it in GitHub Desktop.
Run the same command on multiple Heroku apps via heroku cli
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 | |
# | |
# A command to run a heroku CLI command for multiple apps | |
# | |
# USAGE | |
# $ heroku_multi config:set FOO=bar -a app-1 two-app three-apps | |
# | |
i=0 | |
position=0 | |
async=0 | |
for arg in "$@"; do | |
if [ "$arg" = "-a" ]; then | |
position=$i | |
let ++position | |
let ++position | |
fi | |
if [ "$arg" = "--async" ]; then | |
async=$i | |
fi | |
let ++i | |
done | |
if [ "$async" -gt "0" ]; then | |
echo "=====> Executing asynchronously" | |
fi | |
if [ "$position" -gt "0" ]; then | |
apps=${@:$position} | |
let --position | |
commands=${@:0:$position} | |
for arg in $apps; do | |
if [ "$arg" = "--async" ]; then | |
continue | |
fi | |
echo "=====> heroku ${commands} -a ${arg}" | |
if [ "$async" -gt "0" ]; then | |
heroku "${@:0:$position}" -a $arg & | |
else | |
heroku "${@:0:$position}" -a $arg | |
fi | |
done | |
fi | |
if [ "$i" -lt "2" ]; then | |
echo "Usage: heroku_multi <command> -a app [app] [app...] [--async]" | |
echo "" | |
echo " Passing the --async flag will spawn a background shell" | |
echo " for each app command, executing asynchronously" | |
echo "" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment