Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Windows DOS Batch

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
LeeNukes
LXF regular


Joined: Sun Jun 21, 2009 9:11 pm
Posts: 954
Location: At the bar

PostPosted: Tue Feb 02, 2010 8:30 pm    Post subject: Windows DOS Batch Reply with quote

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

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:

@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%
pause
IF %_space% LEQ 536870912000 GOTO :START ELSE EXIT

:START
@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 \\127.0.0.1 %_sid% /delete

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

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


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:
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
_________________
Join GiffGaff and get 5 free credit
Back to top
View user's profile Send private message
LeeNukes
LXF regular


Joined: Sun Jun 21, 2009 9:11 pm
Posts: 954
Location: At the bar

PostPosted: Wed Feb 03, 2010 9:33 pm    Post subject: Reply with quote

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.

Odd.
_________________
Join GiffGaff and get 5 free credit
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast