Automate config changes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Automate config changes
# 1  
Old 02-05-2007
Question Automate config changes

Hi All,

I have stooopidly agreed to automate our release process (which though easy is a pain).

The config file has a simple structure, below, each section can have upto 20 parms. The release doc will have the section name and parm to be changed.
What I want is to read the list of changes and then make the edit. I can do the auto edit (done before) I'm just struggling to do the find and read next line.

I'll find the section name and then read then next lot of lines, make the edits and do this until I find the next section name , where I start the edits again.
I'm finding the section based on the "^[" but I'm not sure how to continue the read assuming the ^ not equal to ^[. Any ideas?????

[Section1]
parm=value
parm2=value
parm3=value
[Section2]
parm=value
parm2=value
parm3=value
# 2  
Old 02-05-2007
Try this sed command:
sed -n -e '/^\[Section1\]/{;n' -e ':a' -e 'p;n;s/^\[Section//;t' -e'ba' -e'}' data

You should cut and paste since the syntax is a little tricky. And replace "data" with your filename.
# 3  
Old 02-05-2007
Sad that they try to import MS-Windows syntax into Unix
# 4  
Old 02-06-2007
This might get you started.

I assume the config file and the changes file have the same format.
I also assume the changes file is a subset of the config file.

You could convert both of them to a different format.

e.g.

nawk '/\[.*\]/ { SECT=$1; next } { print SECT$0 }' configfile > tmpfile1
nawk '/\[.*\]/ { SECT=$1; next } { print SECT$0 }' changesfile > tmpfile2

Use info from tmpfile2 to make changes in tmpfile1.

When done convert tmpfile1 back to original format and use this file to replace the original config file.

running the command above on the example config file you provided would result in the following output:

tmpfile1:
[Section1]parm=value
[Section1]parm2=value
[Section1]parm3=value
[Section2]parm=value
[Section2]parm2=value
[Section2]parm3=value

Suppose your changes file looks like:

[Section1]
parm2=newvalue1

[Section2]
parm=newvalue2

Again using the command above the output would be:

tmpfile2:
[Section1]parm2=newvalue1
[Section2]parm=newvalue

Thsi puts the config and changes file in a similar format which makes it easy to make the necessary edits.

As mentioned, when the edits are done convert the format back.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

(VS 2008) New build config looking files from other folder build config

Hi Team, My new build configuration always looking for the files from the build where i copied from. please help me to resolve this. I am using Visual studio 2008.It has Qt 4.8. plugins,qml,C++ development I created new debug_new build configuration with additional preprocessor from the... (1 Reply)
Discussion started by: SA_Palani
1 Replies

2. Shell Programming and Scripting

Sftp automate

hi, I am trying to automate a file download process using sftp. There is some logic to download files. 1) I need to login to destination server and then go to folder. 2) find list of files and count 3) using list of files I need to eliminate three selective files and download remaining... (1 Reply)
Discussion started by: getmilo
1 Replies

3. Red Hat

Apache virtual host config vs global config problem

Hi folks, I am trying to configure Apache webserver and also a virtual host inside this webserver. For Global server config: /var/www/html/index.html For virtual host config: /var/www/virtual/index.html Both client10 & www10 are pointing to 192.168.122.10 IP address. BUT, MY... (1 Reply)
Discussion started by: freebird8z
1 Replies

4. UNIX for Dummies Questions & Answers

To automate a process

CAN ANYONE HELP TO SOLVE i wann write a script to automate a process .i.e, to search files in the FTP server and and if files are there and we hav to bring that files to our system. After copying the files in our system we have to upload the data in the tables. I have scripts to load the... (2 Replies)
Discussion started by: nani1984
2 Replies

5. Shell Programming and Scripting

Need a help to automate a task

I need to automate a manual task using shell scripting. The scenario is like :- #!/usr/bin/sh echo "please enter the name of the lab server to test ..." read s ssh $s This is peace of the script which will allow me to login to another server using "ssh". I have a conf file which is having... (4 Replies)
Discussion started by: Renjesh
4 Replies

6. Shell Programming and Scripting

Shell script that will compare two config files and produce 2 outputs 1)actual config file 2)report

Hi I am new to shell scripting. There is a requirement to write a shell script to meet follwing needs.Prompt reply shall be highly appreciated. script that will compare two config files and produce 2 outputs - actual config file and a report indicating changes made. OS :Susi linux ver 10.3. ... (4 Replies)
Discussion started by: muraliinfy04
4 Replies

7. UNIX for Dummies Questions & Answers

Can you automate CVS?

Currently we have a load of files which we manually edit and then commit back into CVS ready for whoever else to edit. I have now made a script which auto-populates these files, however the powers that be still want them accessible via CVS. Is there a way I can automatically commit these files... (7 Replies)
Discussion started by: JayC89
7 Replies

8. Shell Programming and Scripting

parsing config file to create new config files

Hi, I want to use a config file as the base file and parse over the values of country and city parameters in the config file and generate separate config files as explained below. I will be using the config file as mentioned below: (config.txt) country:a,b city:1,2 type:b1... (1 Reply)
Discussion started by: clazzic
1 Replies

9. SuSE

automate ispell

Hello!! Is posible to automate ispell?? I have a lot of misspelled text and I want to launch a script that runs ispell choosing for example the first option, all that automatically. Is possible?? Thanks :) (4 Replies)
Discussion started by: elblo
4 Replies

10. Shell Programming and Scripting

How to automate responses

I would have searched for this but I couldn't really think of what to use for the search text... I've got a situation where I need to automate responses to an executable when running it from a script so that it can be made into a job the operators don't have to interact with. When I run it... (2 Replies)
Discussion started by: djp
2 Replies
Login or Register to Ask a Question