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. 



#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:

[Solved] Android Studio : Android emulator is incompatible with Hyper-V

Have been lately doing Android development. Ran into a minor problem. So I have two machines, a desktop and a laptop. I set the project on ...