I am trying to find a way to generate a CSV table based on output from two or more command line programs (DOS on Windows XP).
I do miscellaneous technical tasks for my university, and the task I am currently working on involves doing an inventory of our computers. I work for the enrollment department, not IT, and IT is extremely uncooperative and bumbling. So we have to do things like inventory all on our own, without access to any central servers, any control panels, etc.
So we're looking for a low-tech way to do inventory, nothing official or fancy but simply a way to automate making a spreadsheet with some crucial info. I've written a batch file that runs systeminfo, passes it one IP at a time from a list, and then has it output CSV data into a file, called, let's say, foo.csv, which we can then open in Excel.
Unfortunately, systeminfo doesn't return some things--for instance, MAC addresses. I can use getmac to do that and output a CSV file, but then I have two tables. I also want some function to return other data (serial numbers in BIOS or something). My goal is to:
1. Make foo.csv have headings for all the programs--systeminfo column headings, getmac column headings, and other arbitrary column headings.
2. For each pass of the FOR loop, I want systeminfo to write its data to the file, then getmac to add its data to the end of the line, and then arbitrary function to add its data to the end of the line.
But somewhere, either at the end or the beginning of the systeminfo output, there's a blank line, and if I simply try to >> the getmac CSV output to the file, it starts on a new line, which means I don't have a functioning table.
Hope me! I've been looking through late-'80s DOS text editing utilities to no avail. I can handle regexes, but just barely, and I don't know any perl/python/etc. There has to be a simple way to do this!
enabledelayedexpansion
for /f "tokens*" %%J in (list_of_IP_addresses.txt) do (
systeminfo_output=systeminfo(%%J)
getmac_output=getmac(%%J)
echo %systeminfo_output%,%getmac_output%>>foo.csv
)
Oh, and adding the headers is easy if you know what they are ahead of time -- just start the file by echoing a header string before you start filling it with output.
posted by harkin banks at 12:11 PM on May 23, 2007