Simple Scripting Help Please

Hi all,

I have need of some advice for a simple script.

I have a Dynamic DNS domain set up with my hosting provider. My hosting provider has provided me with a URL that when loaded updates their system with my current WAN IP. So all I need to do is regularly connect to that URL. How can I best do that with my MikroTik router?

Can I just set up a schedule and put the URL in the “On Event” like this:
Sked.png
From reading the docs though, it seems like the On Event item needs to have a script. So then what do I need to do to write a simple script that just calls the URL? I’ve seen other scripts for DDNS that look to be getting the IP address of the interface, etc. I don’t need to do that. I just need to go to that URL. If done this in a script? Will that work? I tried it and the router seemed to respond OK - I didn’t get any errors or anything…
Script.png
Can someone provide me with some pointers on doing it the correct way?

Thanks.

You need to use the fetch RoS command, likely with a GET (which is default) request, see:
http://forum.mikrotik.com/t/how-to-open-a-url-using-script/115603/1

Perfect. So that’s all I need for the script then - yes? And I need to do it in the script and not in the scheduler - correct?

Something is not right. If I put:

/tool fetch url="https://justaddsoftware.net/cpanelwebcall/****k"

In the console, it works and creates the output file.

However, if I put the same text above in the “source” section of the script in WinBox and then run it, I get no file generated…

How can I know if the script is working properly?

Maybe you can log the returned http code, but have you checked the log ? (fetch commands should create an entry in it)

But it depends also on how logging is configured:
http://forum.mikrotik.com/t/add-more-logged-detail-to-fetch/178998/1

And it becomes a “more advanced” scripting topic, see::
http://forum.mikrotik.com/t/fetch-how-receive-response-code/137754/1

Thanks! I got it working. The logs did the trick. At first, I was just getting a “400 error” but after reading about enabling Fetch in logging, it showed me where my error was occurring. There was a line break for some reason in my URL. Once I took that out, it works!

Good. :slight_smile:

Sometimes it is useful to open the script in the terminal editor as it includes a syntax parser that may (or may not) highlight inconsistencies.