Skip to content

Instantly share code, notes, and snippets.

@danielRomero
Last active March 29, 2017 11:21
Show Gist options
  • Save danielRomero/e22bb4aceb3444315dfc2403b4e29baf to your computer and use it in GitHub Desktop.
Save danielRomero/e22bb4aceb3444315dfc2403b4e29baf to your computer and use it in GitHub Desktop.
Execute command in all AWS EC2 instances with capistrano
#!/bin/bash
# Get all hosts (change regex to fit your structure)
targets=($(cap production ec2:status | egrep -o "ec2.*com"))
for host in `echo $targets`
do
echo fetching logs from ${host}
# Command to execute (example, download logs from all machines)
scp ubuntu@${host}:/var/www/my_app_name/shared/log/production.log ./production${host}.log
done
echo done!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment