Script doesn't execute (completely) on boot

Hello,

I’m trying to create a script which sends WoL packet as soon as an interface becomes active, but it doesn’t seem to work without :delay 20 or so. My intention was to loop around the interface until it has running=true condition and then send the packet, but it doesn’t seem execute at all.

So I’ve created a test script like this to debug the problem:

:log info "START"
:if ([/interface ethernet get [/interface find name="ether2"] running]=true) do={
    :log info "COND - ether2 running"
} else= {
    :log info "COND - ether2 not active"
}
:log info "END"

The thing is - when script is run via scheduler on boot, it only executes: :log info “START” then apparently dies. It does not log neither first, nor second condition and not even :log info “END”. If I run the script manually via “system scheduler run ID” it executes completely. Why exactly is that? I think that even if condition does not exist yet it should simply skip the whole if loop and at least print the END log and not simply die in the middle of the script.

I don’t want to use :delay at the beginning of the script as it may lead to timing issues, plus I want WoL packet to be send the moment interface is in running state and not with some arbitrary delay.

My Test with a Mikrotik-Audiance, concure your Results,

After a Reboot,
the Scheduler was active and executing Scripts ,
approximatly 13 seconds before any of the Interfaces where
Up-and-Running in RouterOS.


I did some Quick test (i am no Scripting-Guru)
You can use a Loop to wait for the Interface to be “Online”
Basic Exemple:

:local I2C "ether2"
:local j 0

:while ( $j <= 2 ) do={
	:if ([/interface/ethernet/find where name=$I2C] = "") do={
		# Interface isn`t online
		log/info message="Interface not online"} else={
		# Interface is Online
		:set $j ($j+1)
		log/info message="Interface Online, Counter $j"}
	:delay 1
};
# Interface is now Up and Running
log/info message="Execute WoL"}

This was mentioned here http://forum.mikrotik.com/t/startup-script-runs-too-early/97753/1