I need help with a batch file
08-09-2009, 11:52
|
#1
|
THE FUNKIEST ON THE BOARD
Join Date: Aug 2005
Location: Canvey Island, Essex
Services: SERVICES FROM 26/08/05
TV XL services
2MB BROADBRAND
UNLIMITED TALK PACKAGE
V+ Service (Since 18
Posts: 1,195
|
I need help with a batch file
Hi,
I'm trying to create a batch file to run a tracert and out the results to a file to see if its going through a different route.
How do I do it and can I loop it say 100 times?
I know this may sound dodgy but I'm trying to prove to our companys IT suppliers that we are using two different proxies and one is being used random and blocking our users from accessing our site.
if we use a user friendly url it causes problems but if you use the server name directly then it does not cause a problem.
please any help much appreciate.
|
|
|
08-09-2009, 11:58
|
#2
|
Inactive
Join Date: Dec 2007
Posts: 18,385
|
Re: I need help with a batch file
To output tracert to a file it's just as simple as adding > XXXX.txt to the end, if you want it to append to a file it's >> XXXX.txt
For example
Code:
tracert bbc.co.uk > trace.txt
will give you the traceroute in a file called trace.txt
If you repeated it with
Code:
tracert bbc.co.uk >> trace.txt
it would add a 2nd tracert to the same file.
Just loop that in a batch file 100 time (there's a few different methods) and you should have you file.
|
|
|
08-09-2009, 11:58
|
#3
|
-
Join Date: Jul 2003
Location: Poole, Dorset
Age: 40
Services: FreeSat+
Tivo
V-Box
VM 60MBit
Posts: 13,365
|
Re: I need help with a batch file
A tracert will not show 2 different web proxies though?
|
|
|
08-09-2009, 12:06
|
#4
|
THE FUNKIEST ON THE BOARD
Join Date: Aug 2005
Location: Canvey Island, Essex
Services: SERVICES FROM 26/08/05
TV XL services
2MB BROADBRAND
UNLIMITED TALK PACKAGE
V+ Service (Since 18
Posts: 1,195
|
Re: I need help with a batch file
yeah but maybe its a firewall somewhere and it can give me some IP addresses I could chekc with the support team.
Thanks Kymmy how do I loop that.
---------- Post added at 12:06 ---------- Previous post was at 12:01 ----------
Graham what do you suggest I try to trace the connection my pc to my server?
|
|
|
08-09-2009, 12:12
|
#5
|
Inactive
Join Date: Dec 2007
Posts: 18,385
|
Re: I need help with a batch file
Set a variable, increment it by one, check within a loop if it gets to 100 if so then point past the loop
Not done batch files for years but something like
Code:
@echo off
set /a var=%1
:LOOP
if %var% gtr %100 goto :END
tracert bbc.co.uk >> trace.txt
set /a var+=1
goto LOOP
:END
Grabbed the code from a quick search as I've not done batch files for a long, long, long, long time (since dos 5  ) but it's basicallya simple
set VAR to 1, loop start, if var is greater than 100 then goto end, tracert to file, add 1 to VAR, goto loop, end
|
|
|
08-09-2009, 12:31
|
#6
|
THE FUNKIEST ON THE BOARD
Join Date: Aug 2005
Location: Canvey Island, Essex
Services: SERVICES FROM 26/08/05
TV XL services
2MB BROADBRAND
UNLIMITED TALK PACKAGE
V+ Service (Since 18
Posts: 1,195
|
Re: I need help with a batch file
hmm that code seems logical but it does not seem to be doing anything. If I run just the tracert by itself it writes the results to the file but if I place that in the loop it does not create the file and does not append anything to it.
Any ideas?
I really need to get some good reference on batch files. They can be really useful.
---------- Post added at 12:31 ---------- Previous post was at 12:31 ----------
how can I append the VAR value to the file as well ?
|
|
|
08-09-2009, 12:54
|
#7
|
Inactive
Join Date: Dec 2007
Posts: 18,385
|
Re: I need help with a batch file
replace trace.txt with %%var (each % represents a digit)
---------- Post added at 12:54 ---------- Previous post was at 12:50 ----------
as I said though it has been a long, long, long time since I did a batch file
It seems to have a problem with the IF statement, I'm sure that one of the usual programmers will be round shortly
|
|
|
08-09-2009, 13:08
|
#8
|
Inactive
Join Date: Dec 2006
Location: Lincoln UK
Age: 76
Services: 50Mb, TV & Phone
Posts: 3,673
|
Re: I need help with a batch file
Since the loop appends to a file it expects to find it existing. Try creating an empty file with that name before running the bat.
|
|
|
08-09-2009, 13:19
|
#9
|
THE FUNKIEST ON THE BOARD
Join Date: Aug 2005
Location: Canvey Island, Essex
Services: SERVICES FROM 26/08/05
TV XL services
2MB BROADBRAND
UNLIMITED TALK PACKAGE
V+ Service (Since 18
Posts: 1,195
|
Re: I need help with a batch file
Hi David,
I tried that and still no luck. This is my batch file. Does it not need some sort of pause to process it?
Code:
@echo off
set /a var=%1
:LOOP
if %var% gtr %100 goto :END
tracert xxxxxxx.xxx >> d:/traceresults.txt
set /a var+=1
goto LOOP
:END
|
|
|
08-09-2009, 13:40
|
#10
|
cf.mega poster
Join Date: Mar 2006
Location: Oslo, Norway.
Age: 36
Services: Canal Digital: 50/10
Posts: 7,577
|
Re: I need help with a batch file
With vbscript and batch:
vbscript :
Code:
dim i
dim wsh
for i = 0 to 99
Set Wsh = WScript.CreateObject("WScript.Shell")
Wsh.Run "traceit.bat", 1
WScript.Sleep 15000
next
And now the batch, call it "traceit.bat":
Code:
tracert bbc.co.uk >> trace.txt
Place both in same folder. There is a 15sec delay between each tracert t give it time to complete.
---------- Post added at 14:40 ---------- Previous post was at 14:36 ----------
Want to make it silent as well? Just tells you when it's done...:
VBscript :
Code:
dim i
dim wsh
for i = 0 to 99
Set Wsh = WScript.CreateObject("WScript.Shell")
Wsh.Run "traceit.bat", 0
WScript.Sleep 15000
next
msgbox "Completed Tracerts!"
|
|
|
08-09-2009, 13:58
|
#11
|
THE FUNKIEST ON THE BOARD
Join Date: Aug 2005
Location: Canvey Island, Essex
Services: SERVICES FROM 26/08/05
TV XL services
2MB BROADBRAND
UNLIMITED TALK PACKAGE
V+ Service (Since 18
Posts: 1,195
|
Re: I need help with a batch file
Am I'm right in thinking I need to run the vbScript? how do I create the vbscript file?
Sorry I'm more of a pl/sql coder.
|
|
|
08-09-2009, 14:02
|
#12
|
Inactive
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
|
Re: I need help with a batch file
create the VBScript file using notepad (or similar) and save it as '<filename>.vbs'.
You should then just be able to double-click it to run it.
|
|
|
08-09-2009, 15:14
|
#13
|
THE FUNKIEST ON THE BOARD
Join Date: Aug 2005
Location: Canvey Island, Essex
Services: SERVICES FROM 26/08/05
TV XL services
2MB BROADBRAND
UNLIMITED TALK PACKAGE
V+ Service (Since 18
Posts: 1,195
|
Re: I need help with a batch file
thanks I've run that and counted the entrys and they is no way there is 100 entrys in the txt file.
Any ideas why there would be some missing?
|
|
|
08-09-2009, 16:12
|
#14
|
step on my trip
Join Date: Jul 2003
Posts: 3,757
|
Re: I need help with a batch file
did you give it enough time tio run fully?
__________________
“Most people don’t listen to understand. They listen to reply. Be different.”
- Jefferson Fisher
|
|
|
08-09-2009, 16:16
|
#15
|
THE FUNKIEST ON THE BOARD
Join Date: Aug 2005
Location: Canvey Island, Essex
Services: SERVICES FROM 26/08/05
TV XL services
2MB BROADBRAND
UNLIMITED TALK PACKAGE
V+ Service (Since 18
Posts: 1,195
|
Re: I need help with a batch file
I left it with the 15sec delay but I just counted 12 entries. I did take around 20mins to run before I got the msgbox saying it was complete.
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT +1. The time now is 18:05.
|