Page 1 of 1

An Attempt to deploy a project using a shell script

Posted: Wed Jun 13, 2007 11:27 am
by rameshrr3
I have made a vague attempt at creating a shell script to deploy a new project , along with its 'user-defined' environment variables and jobs. Is ther any better way of doing it? Apart from capturing status codes of commands and validating input arguments? This is a 'forecasted' requirement from my client.


The file containing environment variable definitions ${4} is supposed to be created from the output of

Code: Select all

'dsadmin -listenv <projectName>' | grep "UD var prefix String" 
command

The Code for the 'deployment script' follows

Code: Select all

#!/usr/bin/ksh
# DSDeployProject.sh ( Rudimentary Script to deploy a new project)
# Assumes an already exported DSX file placed in an unix folder
# Assumes a Environment variable file 
# with records in NAME=VALUE pairs
# For simplicity all env variables are asusmed to be of string type
# Prompt Text is a default value , to be filled up by admin later
# For Simplicity , i assume user gives valid argument values!
#$1 is Name of new Project To be created
#$2 is the path of the Project Directory
#$3 is the dsx file to be imported( abosolute path)
#$4 is the ENV file for environment variable details
#(Can be filled with output of `dsadmin -listenv SourceProject > $4` command
# SYNTAX ./DSDeployProject.sh <ProjectName> <Project Directory Path> <DSX FilePath and Name> <ENV File name with "NAME=VALUE" records>

dsadmin -createproject $1 -location $2
dsjob -import $1 $3 -OVERWRITE

var_linecount=`cat $4 | wc -l`
echo $var_linecount

_i=1

echo 
while true
do
   echo $_i
   var_Name=`awk 'NR=='${_i}'' $4 |awk -F= '{ print $1 }'`
   var_Value=`awk 'NR=='${_i}'' $4 |awk -F= '{ print $2 }'`
   echo "Creating ENV Variable" $var_Name "=" $var_Value
   dsadmin -envadd $var_Name -type STRING -prompt "Enter Prompt Text" -value "$var_Value" $1 
let _i='_i+1'

if test $_i -gt $var_linecount
then
 echo "Loop Ended"
 exit 0
fi
done
How can i work around the limitations of the dsadmin -listenv command? Is there some better way of doing a deployment script?

Posted: Wed Jun 13, 2007 3:49 pm
by ray.wurlod
What do you believe the "limitations of the dsadmin -listenv command" to be?

Does the script work in its present form?

Posted: Thu Jun 14, 2007 6:18 am
by rameshrr3
The dsadmin -listenv command does not give me the environment variable prompt string and type
( Encrypted/String) . It gives me only a list of
NAME=VALUE pairs

As far as testing goes:
I have been able to test so far much of the entire script( creating environment variables from and env file, importing a dsx file etc into an already created project) except for the project creation part, for which i do not have sufficient privileges.

Of course the dsenv is sourced in the admin user's profile file.So I dont have to source it again in the script.


The script will eventually be run by a user with admin privelege. I will be adding the exception handling and some basic argument validation clauses too.



Thanks
Ramesh

Posted: Thu Jun 14, 2007 3:00 pm
by ray.wurlod
You could always read and parse the environment variable definitions (maybe only the ones from -listenv) from the DSParams file.

Posted: Fri Jun 15, 2007 6:36 am
by rameshrr3
All variables that will be of encrypted type will be passwords. All such variable names will have _PWD in their names, hence i probably will scan the output of the dsadmin -listenv for those user variables that end with _PWD. For Prompt string, will use the environment variable name itself for now.

Thanks
Ramesh

Posted: Fri Jun 15, 2007 6:51 am
by chulett
I'm curious about this 'forecasted requirement' from your client. What exactly is this all for? How often does one need to 'deploy' a project? I know some folks have many projects, sometimes way too many in my opinion, but hey - different strokes. The need for new projects is pretty rare around here.

As noted, just mostly curious. :wink:

Posted: Fri Jun 15, 2007 3:06 pm
by ray.wurlod
:idea: A company like Peoplesoft would have exactly such a requirement.

Posted: Mon Jun 18, 2007 5:30 am
by rameshrr3
When you have a client that is 'command line happy', where a script based solution, however rarely used, is considered the best, probably because it gives them a chance to show their geek ability with 'install' scripts. I Spent almost a day getting those single quotes right.:x .

On the flip side , and much to the disappointment of the 'client', there is not a straightforward & convinient way of exporting a project from unix command line.(At least in v 7.51A)

Posted: Mon Jun 18, 2007 5:42 am
by ray.wurlod
To quote the Sergeant-Major from "It Ain't 'alf Hot Mum":
Sergeant-Major Tudor Bryn 'SHUT UP!' Williams wrote:Oh dear. How sad. Never mind.