Skip to content

Instantly share code, notes, and snippets.

@tlatsas
Last active August 29, 2015 13:57
Show Gist options
  • Save tlatsas/9596189 to your computer and use it in GitHub Desktop.
Save tlatsas/9596189 to your computer and use it in GitHub Desktop.
Mange agents with ease
#!/bin/bash
prefix=$(hostname|tr '[:upper:]' '[:lower:]')-$USER
agents=(
"$prefix-agent1"
"$prefix-agent2"
"$prefix-agent3"
"$prefix-agent4"
)
case "$1" in
start)
cmd='up'
;;
stop)
cmd='halt'
;;
status)
cmd=$1
;;
*)
echo "Usage: $0 {start|stop|status}"
exit 1
esac
pushd ~/bitbucket/etravel-nefos &> /dev/null
for agent in "${agents[@]}"
do
vm_state=$(vagrant status $agent | grep '^itdev' | cut -d' ' -f2)
if [[ $vm_state == "not" ]]; then
echo "==> $agent agent is not created, skipping.."
continue
fi
echo "==> Running vagrant $cmd for VM $agent"
vagrant $cmd $agent
done
popd &> /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment