Fetch Status

I am looking for a way to enable or disable a firewall rule depending on a successful or failed tool fetch.

When I run the tool fetch itself from the terminal I see the status: finished or status:failed response. Is there a way to get this data and use it as the trigger to enable or disable the desired firewall rule.



Thanks

you can put output of fetch into variable and then pick part of it and do comparison.

how can I put?
How can I do that?

for example..

http://gregsowell.com/?p=3329

you can put output of fetch into variable and then pick part of it and do comparison.

how I can put output od fetch into variable
I want check status od fetch
(status: finished)
and then continue my script

reg.

function “get status” is required

Perhaps some hint or example.

reg.

Unfortunately it is not possibel to get that status. And if fetch fails script stops executing immediatly.

So only way to check if fetch succeeded or failed is run in one script fetch and then run another script which checks if fetch fetched a file to the router. If there is a file then fetch succeeded otherwise fetch failed.

first add a sccript with

/tool fetch url="http://www.example.com/test.html" mode=http

then add other script with

:local checkpage "test.html";
:local found "0";
:foreach i in=[/file find] do={
	:local filename [/file get $i name];
	if ( $filename = $checkpage) do={ :set found "1"; :log info "found"; }
}
:log info "$found";
if ( $found = "0" ) do={ :log info "Disable rule, service down"; /ip firewall filter disable 0 } else={ :log info "Enable rule, service up"; /ip firewall filter enable 0; }
/file remove $checkpage;

from http://gregsowell.com/?p=3329

  1. what if the router could not retrieve file from proxy ? is there a way to just check the port is open ?

  2. writing a file periodically may damage flash memory of router .

Use keep-result=no then it will not write anything to flash.

Then how we check the file is downloaded or not ?

see status message.

how we use this status message in script when the status is failed my script finished

:global myStr;
:set myStr  [ /tool fetch url="http://xxx.xxx.xxx.xxx/index.html/" port=3128  mode=http  keep-result=no ];
:if ( :put [:len $myStr] != 0 ) do={ :put "(port close)"}
:if ( :put [:len $myStr] = 0 ) do={ :put "(port open)"}

when a file downloaded status not finish myStr length return 0
but when file not downloaded or port is closed script finish and nothing return and exit script done
please help how I can receive open port message without download a page

With scripting can we read the status massage ?

yes I want to store output in my variable

not possible to store result or downloaded file into variable. Maybe future RouterOS versions will have that capability, but currently it is not possible and there is no time-frame when it could become available.

please guide me to check port with script and run command after check it
thank u janisk