Tracert
Moderator: DosItHelp
-
- Posts: 7
- Joined: 19 Jun 2017 08:48
Tracert
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!
@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!
Re: Tracert
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
-
- Posts: 7
- Joined: 19 Jun 2017 08:48
Re: Tracert
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?
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?
Re: Tracert
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
https://ss64.com/nt/tracert.html
Steffen
-
- Posts: 7
- Joined: 19 Jun 2017 08:48
Re: Tracert
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?
Re: Tracert
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
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
-
- Posts: 7
- Joined: 19 Jun 2017 08:48
Re: Tracert
WOW 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 .
Re: Tracert
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
Steffen
-
- Posts: 7
- Joined: 19 Jun 2017 08:48
Re: Tracert
All right! I see its working- I close window too early! Silly me! Thats what I was looking for Thank You Steffen!
Re: Tracert
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
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
-
- Posts: 7
- Joined: 19 Jun 2017 08:48
Re: Tracert
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- 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!
Re: Tracert
I guess, you are starting the batch file from your desktop:Sandokai86 wrote:"CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Windows Directory.
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.
You already mentioned that in your opening post:Sandokai86 wrote:I used tracert because ping was not respondig and gave me Request timed out message.
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.
Depends on your database.Sandokai86 wrote:Is it any other way which I can check is my database is online?
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
-
- Posts: 7
- Joined: 19 Jun 2017 08:48
Re: Tracert
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!
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!