Solved

Script to parse csv file and generate batch files

Posted on 2012-03-29
3
728 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 51

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 51

Expert Comment

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

~bp
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

746 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

15 Experts available now in Live!

Get 1:1 Help Now