Hi guys.
Out of curiosity I want to test my ISP stability/uptime. Easiest way I think of is to run scheduler with ping 8.8.8.8 every few seconds, and report if there is output other than normal ping reply.
This is what I came up with:
:local file
:local time
:local date
:set time [/system clock get time]
:set date [/system clock get date]
:local file ([:pick $date 7 11]."-".[:pick $date 0 3]."-".[:pick $date 4 6])
:if ([/ping 8.8.8.8 count=5] = 0) do={
:log error "Ping error"
/file print file="$file"
:delay 1s
/file set [find name~"$file"] contents=$time
}
:log error “Ping error.” ← this I need to see it on speed in log file, marked with red color.
FIle is created but every time when ping fails it overwrite file with fresh time.
I need it to work like >> output.txt in cmd so it will write new line at the end instead of overwriting whole file. Is that doable? I want to have separate txt file for every day.
This will work until the file gets to a certain size, then it will fail with all new data falling down the bitbucket. String variables in scripting are limited in size.
After 13 years and multiple courses on the MikroTik, I know of none. The routerOS file system is insanely primitive, and the scripting language seems purposely written to ignore it. The /file edit command can’t handle a file significantly larger than a system note – not even an average export file for a more than trivial configuration. You cannot even create a folder without resorting to awkward tricks in FTP. At best, a script might be able to use a file to store a semaphore or two.
That was my first idea and I did it that way as I already have few telegram informations implemented. It was working pretty ok on test IP 8.8.8.88. All “unreachable” messages arrived to me via telegram.
But when I moved it from DEV to PROD it stopped to work. At begining I did not know why. Turns out You need an internet connection for sending telegram messages… You get the point now, right?