Solved

Script to parse csv file and generate batch files

Posted on 2012-03-29
3
733 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 54

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 54

Expert Comment

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

~bp
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to dynamically set the form action using jQuery.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

749 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