Add VAR to bach file

May 10, 2011 at 21:17:54
Specs: Server 2008 R2
Hi,

I have been looking around and getting stuck. I have a smile batch file to track how many open connections are on a webserver.

echo %time% >>connections.log
netstat -an | find "80" | find /C "ESTABLISHED" >>connections.log
timeout /t 15
connections.bat

The connections.log file comes out like this: (on my personal PC)

13:50:32.17
6
13:53:48.03
5
13:54:03.19
10
13:54:18.18
10
13:54:33.15
9
13:54:48.16
9
13:55:03.14
9

I also have another batch that starts at 23:59 each day that renames the connections.log to the date.

What I would like to do is have the output file with no CR/LF so I could format it to be a CSV.

The problem I have is trying to get the netstat output into the form of a variable if I could then all I need to do is change the echo line after the netstat and set it to:

echo %time%,%concvar% >>connections.log

If anyone knows if this can be done please let me know.


See More: Add VAR to bach file

Report •

#1
May 11, 2011 at 08:00:02
@echo off
setlocal enabledelayedexpansion

FOR /F "delims=" %%A IN ('netstat -an ^| find "80" ^| find /C "ESTABLISHED"') DO (
    ECHO !time!,%%A >>connections.log
)
timeout /t 15
connections.bat

When your only tool is a hammer, every problem looks like a nail.


Report •

#2
May 12, 2011 at 06:36:52
Thanks for that worked well on the 1st pass, after the first 15 seconds it started adding CR/LF, so I made a quick work around and just moved the timout /t 15 to another batch and added a call line and just made that batch loop instead. Which is easyer for task manager to kill if it needs to.


Thanks again


Report •
Related Solutions


Ask Question