Posts Tagged: property


15
Mar 10

How to fetch .property file content in bash script

Recently I had a task – implementation of automated deployment procedure to dev/stagin environment.

1) Update server’s source code to the latest version available
2) Create/recreate DB(if necessary) with certain db access parameters.
3) Implement all the latest SQL delta schema updates(via LiquiBase).

My main idea was to reduce duplicity in config management as much as possible.
So I decided to store all db config data in one property file.

nikita@laptop:/var/www/fooproject# cat build.properties
database.port = 3306
database.name = fooproject_devel
database.username = foo_username
database.password = foo_password

This is how I pass parameters from property file to my custom bash script:

nikita@laptop:/var/www/fooproject# cat build.xml

<project name=“Foo” default=“build” basedir=“.”>

    <property file=“build.properties”/>
   
    <target name=“recreate-db”>
        <exec executable=“expect” dir=“${basedir}” failonerror=“on”>
            <arg line =“recreate-db.sh” />
            <arg line =“${database.username}” />
            <arg line =“${database.password}” />
            <arg line =“${database.name}” />
        </exec>
    </target>
</project>

nikita@laptop:/var/www/fooproject# cat recreate-db.sh
#!/usr/bin/expect

set username [lindex $argv 0]
set password [lindex $argv 1]
set database [lindex $argv 2]

That’s it.