Community discussions

MikroTik App
 
martking
just joined
Topic Author
Posts: 18
Joined: Mon Apr 03, 2017 8:54 pm

Creating a loop in script

Fri Mar 23, 2018 12:57 am

Hi All a little help with a Loop

I have the below to detect if the /ip cloud has updated correctly after i had a problem with it not updating when my public ip changed. As I am trying to learn scripting I thought id try and write a solution and came up with the below.

This works perfectly except id like to put the script into a loop where the if option is

log info "forcing ip update";\
/ip cloud force-update ;\
delay "10" ;\
:local working "updated" ;\
:local status [/ip cloud get status] ;\
log info "IP Update forced status is $status" ;\

if (status !=working) \
do={:log error "Update IP to DNS Name has failed status is $status entering loop to resolve issue"; \
:log error "Sleeping for 10 seconds"; \
delay "10"; \
:log warning "forcing update again"; \
/ip cloud force-update;} \
else={:log warning "ip has been updated successfully"}

I have tried using

while (status !=working) \
do={:log error "Update IP to DNS Name has failed status is $status entering loop to resolve issue"; \
:log error "Sleeping for 10 seconds"; \
delay "10"; \
:log warning "forcing update again"; \
/ip cloud force-update;} \
else={:log warning "ip has been updated successfully"}

but i dont seam to be able to make it loop can anyone help please