Community discussions

MikroTik App
 
rmichael
Forum Veteran
Forum Veteran
Topic Author
Posts: 718
Joined: Sun Mar 08, 2009 11:00 pm

dump traceroute to file

Tue Dec 14, 2010 12:30 am

Is there a way to output traceroute to a file instead of the terminal? I want netwatch run traceroute everytime delay is longer than xxx ms...

TIA
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7038
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: dump traceroute to file

Wed Dec 15, 2010 4:08 pm

Currently from router itself it is not possible.
 
wifi442
Frequent Visitor
Frequent Visitor
Posts: 81
Joined: Tue Jan 12, 2010 11:01 pm

Re: dump traceroute to file

Fri Sep 09, 2011 12:02 am

I need to monitor our connection that is at a data center. Data center has a RB1100 installed. They are asking for traceroutes whenever the latency jumps up so they can troubleshoot. Is there any way for netwatch to run and save a traceroute when pings drop? I am always away from the computer when the problem occurs. There must be a way yes?
 
changeip
Forum Guru
Forum Guru
Posts: 3829
Joined: Fri May 28, 2004 5:22 pm

Re: dump traceroute to file

Tue Nov 01, 2011 6:25 am

i need this badly too ...
 
shdwmstff
newbie
Posts: 48
Joined: Wed May 30, 2012 12:00 am

Re: dump traceroute to file

Thu Dec 17, 2015 5:16 pm

Did you ever find a solution for dumping the traceroute to a file.
I have a similar situation where I see a GRE tunnel dropping and want to confirm where in the traceroute it is
getting dropped.

Thanx
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7038
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: dump traceroute to file

Thu Dec 17, 2015 5:21 pm

You still can't from console. But you can get traceroute data from API.
 
User avatar
PaulsMT
MikroTik Support
MikroTik Support
Posts: 282
Joined: Tue Feb 10, 2015 3:21 pm

Re: dump traceroute to file

Fri Dec 18, 2015 10:13 am

You can also save console output with :execute command. With this example you will get 5 second traceroute output saved to TRACEROUTE.txt.

:execute {/tool traceroute 8.8.8.8 duration=5} file=TRACEROUTE
 
shdwmstff
newbie
Posts: 48
Joined: Wed May 30, 2012 12:00 am

Re: dump traceroute to file

Fri Dec 18, 2015 7:29 pm

WHOLEY FANTASTIC-NESS!!!!


it works on 6.33
but not on 6.29
I suspect some weird version bug... but that gets me in the right direction.
curious if it will append...for me but , I'm not complaining.!

Thank you
 
shdwmstff
newbie
Posts: 48
Joined: Wed May 30, 2012 12:00 am

Re: dump traceroute to file

Fri Dec 18, 2015 10:49 pm

ok I have been having a problem where a remote circuit fails intermittently and is causing packet loss.
but by the time I get to the device I don't see any of the errors and can't pinpoint where the failure is occuring.
And as always the upstream gives me the DE-FACTO "Everything is running clean" line.

So I needed to be able to run a trace at the moment the failure happened to see what is failing.
had a heck of a time getting the router to script what I needed so I figured I'll let people know.



Ok Doing this will let you run netwatch and post the output data to a text log file. netwatch,.0.txt

Then if netwatch fails it will run a ping to the tested ip address (count set to 100 but you can change it) ping-fail.txt

It will also execute a traceroute to the device and write the traceroutes to a file. "TRACEROUTE.txt"

Need to be running 6.33 or higher to get it all to work.
the ":execute" command only works after 6.30




Do this to create the netwatch logging option. (this log will stay and get appended, and time stamped)

/system logging action add disk-file-count=100 disk-file-name=netwatch, name=netwatch target=disk

/system logging add action=netwatch topics=script,info



Then create a netwatch instance to 8.8.8.8

put this in the "up script" area

:log info "\rNW-8.8.8.8 up\r";

put this in the "down script" area

SCRIPT-PING-TRACE


Create a Script called "SCRIPT-PING-TRACE" or call it what you want and make it match above
put this in the script. (the trace and ping logs will get overwritten each time this occurs , so you will need to get to them quick)

:log info "\rNW-8.8.8.8 down\r";
:execute {/ping 8.8.8.8 count=100} file=ping-fail;
:execute {/tool traceroute 8.8.8.8 duration=5} file=TRACEROUTE




I hope this helps anyone who has a similar problem.
 
User avatar
PaulsMT
MikroTik Support
MikroTik Support
Posts: 282
Joined: Tue Feb 10, 2015 3:21 pm

Re: dump traceroute to file

Mon Dec 21, 2015 9:55 am

WHOLEY FANTASTIC-NESS!!!!


it works on 6.33
but not on 6.29
I suspect some weird version bug... but that gets me in the right direction.
curious if it will append...for me but , I'm not complaining.!

Thank you

:execute is a new feature, you will find it only starting from RouterOS 6.30

By the way, to be sure that :execute command will not overwrite the output file (if script is executed more then once), add some dynamic text to the file name, for example clock..

:execute {/tool traceroute 8.8.8.8 duration=5} file=([/system clock get time]."_"."filename")
 
mvalsasna
just joined
Posts: 18
Joined: Tue Sep 30, 2014 2:10 pm

Re: dump traceroute to file

Wed Apr 26, 2017 5:45 pm

not working in 6.33 : create an empty file
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26289
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: dump traceroute to file

Thu Apr 27, 2017 10:08 am

not working in 6.33 : create an empty file
works fine in 6.38
 
pkelly1603
Frequent Visitor
Frequent Visitor
Posts: 96
Joined: Mon Jun 15, 2009 11:13 pm

Re: dump traceroute to file

Thu Nov 29, 2018 9:47 pm

not working in 6.33 : create an empty file
works fine in 6.38
The command below does not work from netwatch in version 6.42.9. Is that due to the security changes where netwatch has limited permission? Is there anyway to run a traceroute from netwatch in up to date versions?

:execute {/tool traceroute 8.8.8.8 duration=5} file=([/system clock get time]."_"."filename")
 
Ehman
Member
Member
Posts: 389
Joined: Mon Nov 15, 2010 10:49 pm

Re: dump traceroute to file

Fri Feb 28, 2020 1:17 pm

Create a Script called "SCRIPT-PING-TRACE" or call it what you want and make it match above
put this in the script. (the trace and ping logs will get overwritten each time this occurs , so you will need to get to them quick)

:log info "\rNW-8.8.8.8 down\r";
:execute {/ping 8.8.8.8 count=100} file=ping-fail;
:execute {/tool traceroute 8.8.8.8 duration=5} file=TRACEROUTE

Any way of putting in timestamps of time and date to print in that txt file aswell after every traceroute count, because i want to make this script run 24 hours for example to pin point an issue on the network, so I'll just jack up the duration up from 5 to alooot more, but I need timestamps please guys, I dunno how to add it myself :?

Thank You
 
Cris@usai.net
newbie
Posts: 42
Joined: Fri Jun 17, 2005 8:25 pm

Re: dump traceroute to file

Fri Feb 28, 2020 5:53 pm

Now my original script was this.
Made 2 files showing the failed pings. and showing the traceroutes.
:log info "\rNW-8.8.8.8 down\r";
:execute {/ping 8.8.8.8 count=10} file=ping-fail;
:execute {/tool traceroute 8.8.8.8 duration=5} file=TRACEROUTE

would love to add the time /date to them but the files can't be appended (not an option in ROS)
I was thinking you could make another script and run it after the first. to add the time to the end of the file.
-- This does work... but I suspect there is a better way to just run the traceroutes and post the time at the end Or begining of the file

:local test [/file get TRACEROUTE contents]
:local tSubject "$[/system identity get name] @ $[/system clock get date] $[/system clock get time]"
:set test ($test . "$tSubject")
/file set TRACEROUTE contents=$test
 
User avatar
nichky
Forum Guru
Forum Guru
Posts: 1275
Joined: Tue Jun 23, 2015 2:35 pm

Re: dump traceroute to file

Mon Oct 31, 2022 2:34 am

@PaulsMT

can u pls modificate that script , it does create file, but i can't paste into the computer
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: dump traceroute to file

Mon Oct 31, 2022 10:58 am

@PaulsMT

can u pls modificate that script , it does create file, but i can't paste into the computer
Because the time have : and the computer do not support that filename.
Is a very bad idea use directly the date and the time as filename, for / and : characters.
Last edited by rextended on Mon Oct 31, 2022 11:06 am, edited 2 times in total.
 
User avatar
nichky
Forum Guru
Forum Guru
Posts: 1275
Joined: Tue Jun 23, 2015 2:35 pm

Re: dump traceroute to file

Mon Oct 31, 2022 11:02 am

@rextended

i dot care about the time/date,all i want from the script is to crate is:
filename1
filename2
filenamx

have u got any idea?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: dump traceroute to file

Mon Oct 31, 2022 11:06 am

:global simplercurrdatetimestr do={
    /system clock
    :local vdate [get date]
    :local vtime [get time]
    :local vdoff [:toarray "0,4,5,7,8,10"]
    :local MM    [:pick $vdate ($vdoff->2) ($vdoff->3)]
    :local M     [:tonum $MM]
    :if ($vdate ~ ".../../....") do={
        :set vdoff [:toarray "7,11,1,3,4,6"]
        :set M     ([:find "xxanebarprayunulugepctovecANEBARPRAYUNULUGEPCTOVEC" [:pick $vdate ($vdoff->2) ($vdoff->3)] -1] / 2)
        :if ($M>12) do={:set M ($M - 12)}
        :set MM    [:pick (100 + $M) 1 3]
    }
    :local yyyy  [:pick $vdate ($vdoff->0) ($vdoff->1)]
    :local dd    [:pick $vdate ($vdoff->4) ($vdoff->5)]
    :local HH    [:pick $vtime 0  2]
    :local mm    [:pick $vtime 3  5]
    :local ss    [:pick $vtime 6  8]

    :return "$yyyy-$MM-$dd $HH:$mm:$ss"
}

:execute "/tool traceroute 8.8.8.8 duration=5" file="$[$simplercurrdatetimestr]_traceroute"
# rememer to wait 1s + traceroute duration before doing other steps
:delay 6s

Creating a script that creates the file filename + n is too complicated compared to doing it as I wrote it.
It is feasible, but every time you have to keep the counter and check that the file does not already exist, etc.
Last edited by rextended on Thu May 11, 2023 1:10 am, edited 2 times in total.
 
User avatar
nichky
Forum Guru
Forum Guru
Posts: 1275
Joined: Tue Jun 23, 2015 2:35 pm

Re: dump traceroute to file

Mon Oct 31, 2022 11:33 am

thanks a lot

Who is online

Users browsing this forum: No registered users and 13 guests