Creating an Easy Lookup Table in a UNIX or Linux Shell Script
A Script for Loading a Group of Variables with Environment-specific Values
As a Configuration Manager, I'm always looking for ways to improve the automation of the builds and deployments of my company's applications. We use scripts to compile the apps, replace certain token strings with environment-specific values, and copy theI wanted to keep it simple so maintenance would be easy. I wanted it to run in a basic command shell (I use 'bash', but most other shells would work as well). UNIX and linux utilities like 'sed', 'awk,' and various xml parsers would have done the job, but they added complexity so I stayed away from them (although I did use 'grep'). The listing below is a simplified version of what I came up with. It takes one parameter representing the target environment, and sets 3 variables: the target server, the target database, and a process user ID. It then prints the new values to the screen for verification (an optional step). In reality, the unsimplified version of this script also defines target directories, service names, and website urls among other things, but this is enough to give you the idea:
Listing 1#!/bin/bash
# Sets environment variables based on lookup string
# Environments: DEV = Development, QA = Quality Assurance,
# UAT = User Acceptance Test, PROD = Production
ENVIRONMENT=$1
# Set server addresses, database names, and user IDs.
line=`grep ^$ENVIRONMENT --- ------------------------ --------- ----------
DEV dev.myapp.mybusiness.com myappdev devappuser
QA qa.myapp.mybusiness.com myappqa qaappuser
UAT uat.myapp.mybusiness.com myappuat uatappuser
PROD prod.myapp.mybusiness.com myappprod prodappuser
EOF`
Related information
Shell scripts in UNIX and linux provide a rich set of redirection substitution features, making them well suited for environment-specific tasks.
Most Comments Today
- Death at Disney World in Orlando, Florida Monorails collide one driver has died at the Disney World Theme Park in Orlan... 23 Comments
- Why Would a Web Writer Drop DayLife.Com? Before I share my story with you, dear readers, I want to point out that Dayl... 22 Comments
- Give a Damn Another new song, this one describes the feelings of us who save the world ev... 22 Comments
- Is Obamageddon Coming? The times they are a changin' - but are we hurtling toward Armageddon - or as... 20 Comments
- A Little Good News Today Here is...a little good news today. 18 Comments
- Bachelorette 5 Spoiler: Wes Hayden Spills the Beans About... This week July 6, 2009 episode 8 of the Bachelorette Jillian will finally d... 18 Comments







Rae Lynne Morvay
Posted on 03/29/2008 at 10:03:52 AM
IcyCucky
Posted on 02/28/2008 at 12:02:12 PM
jcorn
Posted on 02/28/2008 at 7:02:36 AM
Nikki
Posted on 02/27/2008 at 2:02:13 PM
Rodney Southern
Posted on 02/22/2008 at 8:02:34 PM
Kim Linton
Posted on 02/21/2008 at 2:02:32 PM
Joe Poniatowski
Posted on 02/20/2008 at 2:02:38 PM
jcorn
Posted on 02/15/2008 at 9:02:02 PM
Louie Jerome
Posted on 02/14/2008 at 2:02:40 PM
Louie Jerome
Posted on 02/14/2008 at 2:02:36 PM