Solved

Script to parse csv file and generate batch files

Posted on 2012-03-29
3
729 Views
Last Modified: 2012-03-29
I have to create a set of batch files for various locations in our firm.  The purpose of the batch files is to create a batch file that can be run to set system-level environment variables on systems.

Here is the CSV format:

location,server,state,db1,db2
downtown,downtownsrv,dc,databasea,databaseb
uptown,uptownsrv,dc,databasea

I would like to have the script to read a line, in the CSV, and create a batch file with the following contents:

setx location=downtown
setx server=downtownsrv
setx state=dc
setx db1=databasea
setx db2=databaseb

Once the bach file is created, I'd like to have the batch file copied to a server location.  Once the copy is complete, the script should go to the next line and do the same thing at a different location until all locations are complete.  The script needs to be flexible enough to add more columns in the future.  

The reason I am creating these batch scripts is so I can use our desktop management suite to run the batch script on our systems.  We cannot use login scripts because we need to have these settings set regardless of whether a user is logged in or not.  Group policy is also not an option, at this moment.
0
Comment
Question by:fbrsupport
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 37782299
Working on a mobile device, but I'll try to get this started.

@echo off
Set CsvFile=c:\temp\csvfile.csv
For /F "skip=1 tokens=1-5 delims=," %%A in (%CsvFile%) do (
  Echo set Location=%%A>%OutFile%
  Echo set server=%%B>>%OutFile%
  Echo set start=%%C>>%OutFile%
  Echo set db1=%%D>>%OutFile%
  Echo set db2=%%E>>%OutFile%
  Copy %outfile% d:\serverloc
)

Open in new window

0
 

Author Closing Comment

by:fbrsupport
ID: 37782690
That was perfect.  I think I was over thinking the solution.  I made some slight modifications to the script but thanks for getting me started.  For the copy command I used xcopy and used the server value in the destination.
0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 37782838
Great, so glad that helped.

~bp
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now