Last active
October 12, 2018 22:24
-
-
Save sodonnell/29b4584cff8419a348cd67df02141418 to your computer and use it in GitHub Desktop.
I really hate dealing with legacy systems. This feels so wrong, and should not exist, but here we are.
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
#!/usr/bin/env bash | |
# | |
# This script is a complete hack to work-around a crappy | |
# old Amazon EC2 instance running a custom CentOS AMI that | |
# was NOT provisioned by Amazon AWS engineers. | |
# | |
# This particular (bain of my existence) server uses | |
# Google's DNS servers in the /etc/resolv.conf file, but | |
# wreaks havoc on the PHP web application when trying to | |
# call mysqli_connect, and often times-out or takes far | |
# longer to resolve than is acceptable for a web application. | |
# | |
# "Let's migrate the MySQL Database to RDS." -they said. | |
# "The 'ClassicLink' feature will work with the new VPC" -they said. | |
# | |
# The simple fact that I had to write this script makes me | |
# die a little bit inside, and cringe at the systems I'm | |
# inheriting from previous engineers where I work. | |
# | |
# Run via root crontab every 20 minutes. 'crontab -e' | |
# */20 * * * * /root/rds.hosts.sync.sh | |
# | |
# Author: Sean O'Donnell <sean.odonnell@seanodonnell.com> | |
# | |
RDSHOST="the-db-that-hates-me.c3ualchrhtne.us-west-1.rds.amazonaws.com"; | |
OUTFILE="/etc/hosts"; | |
LOOKUP=`host ${RDSHOST} | grep "address"`; | |
LOGOUT=/var/log/$0.log | |
# | |
# Only proceed if we indeed had a successful | |
# remote dns look-up. Good luck with that. | |
# | |
date >> ${LOGOUT}; | |
if [ ! -z "$LOOKUP" ]; then | |
# reverse-lookup hostname | |
RDSREVHOST=`echo ${LOOKUP} | awk {'print $1'}`; | |
RDSIPADDDR=`echo ${LOOKUP} | awk {'print $4'}`; | |
HOSTSLINE="${RDSIPADDDR} ${RDSHOST} ${RDSREVHOST}"; | |
echo -e "127.0.0.1 localhost.localdomain localhost" > ${OUTFILE} | |
echo -e "::1 localhost6.localdomain6 localhost" >> ${OUTFILE} | |
echo ${HOSTSLINE} >> ${OUTFILE} | |
echo "Lookup successful. ${OUTFILE} updated." >> ${LOGOUT}; | |
else | |
echo "Lookup Failed." >> ${LOGOUT}; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment