Cable Forum

Cable Forum (https://www.cableforum.uk/board/index.php)
-   General IT Discussion (https://www.cableforum.uk/board/forumdisplay.php?f=19)
-   -   I need help with a batch file (https://www.cableforum.uk/board/showthread.php?t=33655117)

funkyCable 08-09-2009 11:52

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.

Kymmy 08-09-2009 11:58

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.

Graham M 08-09-2009 11:58

Re: I need help with a batch file
 
A tracert will not show 2 different web proxies though?

funkyCable 08-09-2009 12:06

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?

Kymmy 08-09-2009 12:12

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

funkyCable 08-09-2009 12:31

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 ?

Kymmy 08-09-2009 12:54

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

Dai 08-09-2009 13:08

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.

funkyCable 08-09-2009 13:19

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


Druchii 08-09-2009 13:40

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!"


funkyCable 08-09-2009 13:58

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.

Raistlin 08-09-2009 14:02

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.

funkyCable 08-09-2009 15:14

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?

idi banashapan 08-09-2009 16:12

Re: I need help with a batch file
 
did you give it enough time tio run fully?

funkyCable 08-09-2009 16:16

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.

Druchii 08-09-2009 16:17

Re: I need help with a batch file
 
Could be that the tracert is taking longer than 15 seconds to complete... That's the flaw in my code, since the shelling of the batch file doesn't care if it's done or not.

You could set the time limit to 30000 from 15000 in the vbscript file. Or, even make it a full 60000 for 1 a minute.
The problem is that a tracert takes a while to do.

idi banashapan 08-09-2009 16:58

Re: I need help with a batch file
 
It's quite common for hops to time out on tracert then continue once a new route is found

funkyCable 08-09-2009 17:58

Re: I need help with a batch file
 
is there another command I could use its been a while since I did my network+


All times are GMT +1. The time now is 09:22.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum