Skip to content

Instantly share code, notes, and snippets.

@joshbeckman
Last active July 24, 2017 16:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshbeckman/e52a343a667f3660c9495854cba63a6a to your computer and use it in GitHub Desktop.
Save joshbeckman/e52a343a667f3660c9495854cba63a6a to your computer and use it in GitHub Desktop.
Run the same command on multiple Heroku apps via heroku cli
#!/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