I've a task in hand where I've to run a script on all the servers behind a load balancer in aws. We have auto-scaling as well so at the time of high load, new servers get added behind the same load balancer.
The script will run to find out which git repo is set and what is the latest commit id on the server so that we can check if all the servers match the same git repo and commit id.
This is the script which will run on all the servers behind loadbalancer.
#!/usr/bin/env bash
# gets the current git branch
function parse_git_branch() {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/"
}
# get last commit hash prepended with @ (i.e. @8a323d0)
function parse_git_hash() {
git rev-parse --short HEAD 2> /dev/null | sed "s/\(.*\)/@\1/"
}
# DEMO
GIT_BRANCH=$(parse_git_branch)$(parse_git_hash)
echo ${GIT_BRANCH}
Anyone has any idea how can I achieve this or have any previous experience with something similar? Thanks!
0 Answers