Hello guys.
I know some basic scripting in my debian based system and general linux commands, but i am absolutely ignorant with any Mikrotik scripting.
I have a hAP AC 2, with router OS 7.17.2.
I am behind a CGNAT with my ISP, so I am not able to use the built in Mikrotik’s cloud service with the xxx.sn.mynetname.net domain.
Here is a description of what i would like to do:
I need to create a script on my Mikrotik router that checks a URL (e.g., mydomain.com/textfile.txt), reads the content of the text file, and uses an IF statement to perform one of two actions based on the word in the file. The file contains just one word, and I can edit it on my web server. If the word matches a certain condition (true), the script will send a Wake-on-LAN (WoL) command to a specific MAC address in my network. The goal is to wake up a small server that I only need occasionally, rather than keeping it on all the time.
So far i was able to find a command that downloads the TXT file to the mikrotik’s file system.
/tool fetch url="https://domain.com/wol.txt" mode=https http-method=get keep-result=yes
But then i wasted an hour trying to make the router read the contents of the file, for some reason it prints just a blank line, i am stuck there.
I downloaded the TXT file from the mikrotik to my computer, and the file has the word in there, the command is getting the right file with the contents.
This is what i tried so far:
:local content [/file get wol.txt contents];
:put $content
:local content [/file get wol.txt];
:put $content
So this is supposed to put the contents of the text file into a variable and then print the variable contents in the terminal? It just prints a blank line.
I would rather make the mikrotik read the TXT file straight off the web server and put it in RAM instead of downloading a text file every 5 minutes to the router’s file system to avoid stressing the flash memory.
Thank you for any tips.