Sunday, May 11, 2014

Quick and easy bash script to update config file values

We have a service which connects to a database and does its job. As part of company policy we update/change the password for the database every 90 days. Here is a quick and easy script to update the password in all the config files connecting to the database. 

#!/bin/sh

NEW_PASSWORD="P@ssw0rd!!"
SERVICE_HOME_DIR="/opt/services/LogService"
cd $SERVICE_HOME_DIR 

#Password in the config file in the form: Password=OldP@sswd!
current_password=`cat service.config |grep ^Password | awk {'print $1'} `

#echo "Current Password::" $current_password
#echo "New Password::" $NEW_PASSWORD

# sed used to replace the current password by new password in config file
sed -i 's/^Password=.*/Password='${NEW_PASSWORD}'/' service.config

echo "Password successfully changed !!"


Hope this helps. 

No comments:

Using Tcpdump to dump and read network traffic

Another Quick FYI tip. There are many network analyzer/reader utilities available on both Linux and Windows platform. There is of-course ...