DOS Batch file question

Kelemvor

Lifer
May 23, 2002
16,928
8
81
OK, here's the scenario.

I need to get the uptime from around 2300 computers we have. I can use the systeminfo /s command to get it but it takes like 15 seconds per computer. If I just run through a list it's going to take over 8 hours.

I have a TXT file with all the computer names that need to be checked and just run it through a for loop.

Code:
for /f %%A in (ids.txt) do (
  systeminfo /s %%A)

I thought of two other possibilities.

1) If there's a way to have it kick off other commands while waiting for the first one to come back, that would be great. But I don't know that that's possible.

2) I can split the job up into multiple batch files and have them each run a subset of the data. I don't want to have multiple source files though so maybe if I can have the for loop read in every other line or every 4th line, I can just set one to start at 1 then jump to 5, one to start at 2 and jump to 6, etc. However I don't know how to make them read in every X line.

Anyone have any other ideas for me?
 

sao123

Lifer
May 27, 2002
12,656
207
106
doesnt your SMS server report uptime for all collections of all servers and workstations... seems you could just run a collection report and be done.

if you must do this via dos, it would seem much easier to distribute a dos file to each machine, have it collect its own system info into a file, then collect 2300 txt files into one network location. Then a new batch file can open and read each one and copy the data to a single master file.
 

Merad

Platinum Member
May 31, 2010
2,586
19
81
Try something like this:

getalluptimes.bat:
Code:
for /f %%A in (ids.txt) do (
  start /B getuptime.bat %%A)

getuptime.bat:
Code:
systeminfo /s %1 >> output.txt

But I'm rusty on batch files and that totally may not work.
 

Kelemvor

Lifer
May 23, 2002
16,928
8
81
I figured our SMS guy could do it but I guess he's just too busy,.

I ended up figuring it out though.

I basically made 4 batch files that run through my list and each rotates through the data. This way I can just have a whole bunch of batch files running to crank through the data so it doesn't take too long.

Code:
@echo off
setlocal EnableDelayedExpansion
set /a cnt=0

for /f %%A in (ids.txt) do  (
     
 set /a cnt=!cnt!+1
     
  if !cnt! == 1 (
         echo %%A
         systeminfo /s %%A /fo table /nh > %%A.csv
       )
     if !cnt! == 4 (set /a cnt = 0)
  )


Now, is there a way to make one batch file to call all the others? I can't use CALL since that calls the firs tone and then stops until it's done before continuing. I just want something to fire off them all at once. Or I guess I just make a few extra tasks.
 
Last edited:

postmark

Senior member
May 17, 2011
307
0
0
I think you should really take a look at the power shell script that I linked to. It is nearly instant results.
 

Kelemvor

Lifer
May 23, 2002
16,928
8
81
So I'm trying the uptime.exe program and it works great for most sytems. However, I have a couple that are saying something like:

\\PC_Name has been up for: 229 day(s), 23 hour(s), 34 minute(s), 33 second(s)

Estimate based on last boot record in the event log.
See UPTIME /help for more detail.

That date ends up being 12/17/2010 which is when this machine was first brought up.

But when I remote into the machine, I see it just rebooted this morning. And when I do the uptiem with the /s to get the detailed info, it shows me all kinds of Boot events every day for the past few months. No idea why it's not figuring that out.

But for most of them it works well.