Tracert

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Sandokai86
Posts: 7
Joined: 19 Jun 2017 08:48

Tracert

#1 Post by Sandokai86 » 19 Jun 2017 09:46

Hello! Its my first post up here. Please accept my apologies for my spelling errors as English is my second language (unfortunately) I have been looking at this forum all over the place but without success. I still have more questions. I am new in batch programming. I would like to "ping" my database but ping is not responsive to that so I used tracert command. My script looking as follows:

@echo off
Cls
:begin
echo %date% %time%
tracert -h 15 -w 30 my.se.rv.ip
timeout 30
goto :begin

My question is:
How to make it sound when database is offline/or any server between me and server is offline.
Or could you please direct me to some good places as Im stuck :-/
Thank you very much for response!

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Tracert

#2 Post by aGerman » 19 Jun 2017 14:34

Sandokai86 wrote:My question is:
How to make it sound when database is offline/or any server between me and server is offline.

You mean that you want to get a beep if at least one path timed out?

Code: Select all

@echo off &setlocal

for /l %%i in () do ( REM infinite loop
  for /f "delims=" %%j in ('tracert -h 15 -w 30 my.se.rv.ip') do (
    echo(%%j
    for /f "tokens=2-4" %%k in ("%%j") do if "%%k%%l%%m"=="***" <nul set /p "="
  )
  timeout /t 30
  echo(
)

If a line contains 3 asterics instead of the response times a beep or ringtone (depending on your OS) will be generated by the character next to the = of the SET /P command. It's the Bell character (ASCII 07).

Steffen

Sandokai86
Posts: 7
Joined: 19 Jun 2017 08:48

Re: Tracert

#3 Post by Sandokai86 » 19 Jun 2017 14:56

Hello Steffen!
Thank you for your reply! Im on windows 10 [Version 10.0.15063] 64 Bit - apologies that I haven`t mentioned on the first post.
Yes -thats what I mean. Is it any chance to setup restrictions in delay for all servers which my track going through?

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Tracert

#4 Post by aGerman » 19 Jun 2017 15:10

I never used tracert yet. But according to the reference I read on SS64 there is only option -w that you already used.
https://ss64.com/nt/tracert.html

Steffen

Sandokai86
Posts: 7
Joined: 19 Jun 2017 08:48

Re: Tracert

#5 Post by Sandokai86 » 19 Jun 2017 15:15

Great - Thank you! Steffen that probably will be one of the "stupid" questions but why you used REM infinite loop instead goto ? Is it better your way to do loops?

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Tracert

#6 Post by aGerman » 19 Jun 2017 15:33

REM is for remark and is just a command to write comments to your code. The actual infinite loop is the FOR /L loop with the empty pair of parentheses.
You may or may not prefer FOR /L to GOTO. It's just a fact that cmd.exe has to parse your whole script before it finds the label :begin because the search direction is top to bottom beginning at the GOTO command. It resumes searching on the beginning of the script if it didn't find the label after reaching the script end. As you can see GOTO is a performance killer (even if that doesn't make any difference in your case since you suspend the batch execution 30s in each iteration).

Steffen

Sandokai86
Posts: 7
Joined: 19 Jun 2017 08:48

Re: Tracert

#7 Post by Sandokai86 » 19 Jun 2017 15:36

WOW :shock: Good to know! Thank you! I thought that goto is simple but seems your way is more efficient ;-) What I am doing wrong if I get only black screen when I run your script? Feel so noobish - sorry .

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Tracert

#8 Post by aGerman » 19 Jun 2017 15:46

I don't know. It may take a while before you see the output of TRACERT because the FOR /F loop is buffering it before it even begins to process the lines. That means you won't see anything before TRACERT quits.

Steffen

Sandokai86
Posts: 7
Joined: 19 Jun 2017 08:48

Re: Tracert

#9 Post by Sandokai86 » 19 Jun 2017 15:49

All right! :-) I see its working- I close window too early! Silly me! Thats what I was looking for :-) Thank You Steffen!

penpen
Expert
Posts: 1996
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Tracert

#10 Post by penpen » 19 Jun 2017 16:28

In case you (Sandokai86) were not aware of the following:
If ping does not work, then typically SMTP is blocked on a bridge somewhere on the way to your database, and if that is the case tracert should be useless from the "blocking device" onward. I'm not sure if tracert outputs different messages for ICMP packet blocked, and "device down", so you might (or might not) get some wrong result (server down, although it is up, and vice versa).

penpen

Sandokai86
Posts: 7
Joined: 19 Jun 2017 08:48

Re: Tracert

#11 Post by Sandokai86 » 20 Jun 2017 02:44

Hello again! Still have some weird stuff on my screen :-( when I checked at home everything was ok. But now when I changed location all I get is j letter in 18 lines. On the top of my window i can see message: "CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Windows Directory.
Penpen- I used tracert because ping was not respondig and gave me Request timed out message.
Is it any other way which I can check is my database is online?
Thank you in advance for reply!

penpen
Expert
Posts: 1996
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Tracert

#12 Post by penpen » 20 Jun 2017 07:19

Sandokai86 wrote:"CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Windows Directory.
I guess, you are starting the batch file from your desktop:
If your profile is stored locally but on a server or network storage, then don't start your batch from deskstop.
I've only seen this in big organizations and universities; typically in that cases you have a "home directory", which in most cases is assigned to a drive (in most cases i've seen it is the "Z:" drive). You should use that directory.
If the above is not available for you - just ask your admin.

Sandokai86 wrote:I used tracert because ping was not respondig and gave me Request timed out message.
You already mentioned that in your opening post:
All i said is, that ping and tracert are both using the Internet Control Message Protocol (ICMP):
Ping requests, Ping responses and Information Request are control messages of that protocol (0, 8 and 30).

I've never seen, that somebody blocks only single messages of that protocal - instead i've seen blocking all ICMP messages:
So most probably if one of them don't work, then all others won't work also.

Sandokai86 wrote:Is it any other way which I can check is my database is online?
Depends on your database.
In most cases the easiest way to detect if it's reachable by your is to just log into, or if it has a html web frontend, just check if you could browse this html file (which is more secure).

There's no reliable way to check, if something is down (except checking the server logs), because Internet could be (partially) separated (due to defective routers, or something like that); also, your actual location could be not reachable from internet.
Depending on your server structure, you might find http://www.isitdownrightnow.com/ usefull.

penpen

Sandokai86
Posts: 7
Joined: 19 Jun 2017 08:48

Re: Tracert

#13 Post by Sandokai86 » 20 Jun 2017 13:01

Great and detailed answer penpen! Thank you!
You are right- I starting my batch from my desktop- I will move as suggested to my folder ;-) The whole reason why I bother you guys is to know when database are down before all calls to me saying that is down :-/ I can login to my database using html. One more time - thank you!

Post Reply