Generating .csv files for multiple folders

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
smaddela
Posts: 4
Joined: 01 Mar 2015 14:35

Generating .csv files for multiple folders

#1 Post by smaddela » 01 Mar 2015 14:45

Hi,
This is my first task with batch and need help with the following:
I have multiple folders in a directory. Every folder has two files system.kernel.cpu.idlepct and system.memory.free.
I need to generate .csv files for these two files in every folder by running -tmin 20150101 -tmax 20150228 -x on these two files.
Could any of you please help me with this?
Thank you

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Generating .csv files for multiple folders

#2 Post by Squashman » 01 Mar 2015 21:15

smaddela wrote:I need to generate .csv files for these two files in every folder by running -tmin 20150101 -tmax 20150228 -x on these two files.
Thank you

Might want to explain this task with more detail. I have no idea what your comment above means.

smaddela
Posts: 4
Joined: 01 Mar 2015 14:35

Re: Generating .csv files for multiple folders

#3 Post by smaddela » 02 Mar 2015 02:56

Hi,
We have a monitoring tool that runs on client servers. Every month our customer uploads the data collected by our tool for these 10 servers as zipped files on Ftp.
We then unzip these folders and save it in a directory C:\Customer\Server1...C:\Customer\Server8 and so on.These folders have multiple file types *.dats, *.dlls, *.exes etc
But we are interested in generating reports as .csv files for cpu (i.e. system.kernel.cpu.idlepct which is IDLEPCT file) and memory (i.e. system.memory.free which is free file) consumption for every server. To generate these we are currently running the below commands in a notepad (executed as .bat file)
C:\Customer\server1\monitool -tmin 20150101 -tmax 20150228 -x system.kernel.cpu.idlepct > server1_idlepct.csv
C:\Customer\server1\monitool -tmin 20150101 -tmax 20150228 -x system.memory.free > server1_memfree.csv
C:\Customer\server2\monitool -tmin 20150101 -tmax 20150228 -x system.kernel.cpu.idlepct > server2_idlepct.csv
C:\Customer\server2\monitool -tmin 20150101 -tmax 20150228 -x system.memory.free > server2_memfree.csv
.......
........
C:\Customer\server10\monitool -tmin 20150101 -tmax 20150228 -x system.kernel.cpu.idlepct > server10_idlepct.csv
C:\Customer\server10\monitool -tmin 20150101 -tmax 20150228 -x system.memory.free > server10_memfree.csv

The task is now to run a batch script to generate .csv files for every server(folder) that can automatically go through the directory for servernames(folders names) and generate those two .csv files for every server(folder).

I hope this is little clear now.
Thank you.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Generating .csv files for multiple folders

#4 Post by foxidrive » 02 Mar 2015 07:15

Which part are you having trouble with?

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Generating .csv files for multiple folders

#5 Post by Squashman » 02 Mar 2015 09:09

foxidrive wrote:Which part are you having trouble with?

Ditto!
Still not understanding what you are having problems with.

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Generating .csv files for multiple folders

#6 Post by Samir » 13 Mar 2015 12:33

smaddela wrote:The task is now to run a batch script to generate .csv files for every server(folder) that can automatically go through the directory for servernames(folders names) and generate those two .csv files for every server(folder).
I think automatically going through server directories versus having them hardcoded is the task at hand.

A couple of questions:
- Are the server directories the only ones in this particular part of the tree?
- Do the server directories always follow the 'ServerX' nomenclature?
- What is the highest number of the server? Will it increase in the future?

smaddela
Posts: 4
Joined: 01 Mar 2015 14:35

Re: Generating .csv files for multiple folders

#7 Post by smaddela » 16 Mar 2015 13:53

Hi,
Thank you for the reply.
Please find my answers to your questions below:

- Are the server directories the only ones in this particular part of the tree? Yes
- Do the server directories always follow the 'ServerX' nomenclature? Yes
- What is the highest number of the server? Will it increase in the future? 17 and they will not change (as of now)

What we have now is all hard coded. But the idea is to have some kind of loop or functions to make it look simple.

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Generating .csv files for multiple folders

#8 Post by Samir » 16 Mar 2015 14:30

smaddela wrote:Hi,
Thank you for the reply.
Please find my answers to your questions below:

- Are the server directories the only ones in this particular part of the tree? Yes
- Do the server directories always follow the 'ServerX' nomenclature? Yes
- What is the highest number of the server? Will it increase in the future? 17 and they will not change (as of now)

What we have now is all hard coded. But the idea is to have some kind of loop or functions to make it look simple.
This should work with all the rem's removed and executed from c:\customer\:

Code: Select all

for /d %%f in (server*) do
(
rem C:\Customer\%%f\monitool -tmin 20150101 -tmax 20150228 -x system.kernel.cpu.idlepct > %%f_idlepct.csv
rem C:\Customer\%%f\monitool -tmin 20150101 -tmax 20150228 -x system.memory.free > %%f_memfree.csv)
This will result in all the csv files in c:\customer. Is that what you want?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Generating .csv files for multiple folders

#9 Post by foxidrive » 16 Mar 2015 19:07

Samir wrote:This should work with all the rem's removed and executed from c:\customer\:

Code: Select all

for /d %%f in (server*) do
(
rem C:\Customer\%%f\monitool -tmin 20150101 -tmax 20150228 -x system.kernel.cpu.idlepct > %%f_idlepct.csv
rem C:\Customer\%%f\monitool -tmin 20150101 -tmax 20150228 -x system.memory.free > %%f_memfree.csv)
This will result in all the csv files in c:\customer.


Error, Will Robinson!!

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Generating .csv files for multiple folders

#10 Post by Samir » 16 Mar 2015 19:19

foxidrive wrote:
Samir wrote:This should work with all the rem's removed and executed from c:\customer\:

Code: Select all

for /d %%f in (server*) do
(
rem C:\Customer\%%f\monitool -tmin 20150101 -tmax 20150228 -x system.kernel.cpu.idlepct > %%f_idlepct.csv
rem C:\Customer\%%f\monitool -tmin 20150101 -tmax 20150228 -x system.memory.free > %%f_memfree.csv)
This will result in all the csv files in c:\customer.


Error, Will Robinson!!
Where? I ran this locally and it worked fine. :?

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Generating .csv files for multiple folders

#11 Post by Squashman » 16 Mar 2015 20:16

Pretty sure that left parentheses needs to be up on the same line as the DO.

smaddela
Posts: 4
Joined: 01 Mar 2015 14:35

Re: Generating .csv files for multiple folders

#12 Post by smaddela » 17 Mar 2015 09:20

Ran the script but it doesn't work! :roll:

Post Reply