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:

Section 80C TMT 2023(PA) – Standard Deduction amounting to a maximum of Rs 8670 under IT rule

With the recently concluded Tax filing season (which if I may draw parallel to the Christmas holiday season enjoyed by one and all), Indians...