Windows DOS Batch

Code junkies hangout here

Moderators: ChriThor, LXF moderators

Windows DOS Batch

Postby LeeNukes » Tue Feb 02, 2010 8:30 pm

First, sorry for posting this here, I know its not Linux, but I AM using SED :)

What I am trying to do is run a tcpdump (Windump) at certain times and after 15 minutes from that time kill the dump but only if there is enough disk space free.

OK, here is the batch file:

Code: Select all
@echo off

@REM This file will check disk space and start a tcpdump output to days
@REM date and the hour the command was ran. It then kills it and ends.

:: Check for diskspace and make sure there is plenty free

dir | find "bytes free" > diskspace
sed s/,//g diskspace > diskspacenoc
FOR /F "tokens=3*" %%G IN (diskspacenoc) DO SET _space=%%G

echo %_space%
IF %_space% LEQ 536870912000 GOTO :START ELSE EXIT

@REM Set datehour to be the current date and hour
set datehour=%date:~-10,2%%date:~-7,2%%date:~-4,4%_%time:~-11,2%%time:~-8,2%

::delete old schduled tasks output file
del output

:: find any schedules windump commands and output
at | find "Windump" > output

::parse the output file
FOR /F "tokens=1" %%G IN (output) DO SET _sid=%%G

::Delete old scheduled taskkills listed in output
at \\ %_sid% /delete

::schedule new taskkill
at 16:15 TASKKILL /F /IM "Windump.exe"

::run tcpdump
WinDump.exe -s 0 -n -w %datehour%tcpdump

Everything works fine, apart from the disk space check. What happens is a dir is ran and output to a file, the Free Bytes is then copied from that to another file and sed removes the commas from it. I then want to say if there is less then 50GB available just exit, no output, I don't care, just quit. It doesn't see to work.

I have also tried:

Code: Select all
IF %_space% LEQ 536870912000 (EXIT) ELSE (

Any ideas?

IF you want to emulate this, you will need sed and its dependancies and Windump and WinPCap
LXF regular
Posts: 954
Joined: Sun Jun 21, 2009 8:11 pm
Location: At the bar

Postby LeeNukes » Wed Feb 03, 2010 9:33 pm

Hmm, found today that it appears to be treating it a string instead of numbers. If I put in any length of numbers, as long as there are the same amount of numbers there then it will treat it as the same, if I lop one off, then it treats it as less.

LXF regular
Posts: 954
Joined: Sun Jun 21, 2009 8:11 pm
Location: At the bar

Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests