Community discussions

MikroTik App
 
Fluke
just joined
Topic Author
Posts: 4
Joined: Wed Aug 02, 2017 1:46 pm

Script doesn't execute (completely) on boot

Fri Dec 31, 2021 12:11 am

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.
 
ConnyMercier
Forum Veteran
Forum Veteran
Posts: 725
Joined: Tue Dec 17, 2019 1:08 pm

Re: Script doesn't execute (completely) on boot

Fri Dec 31, 2021 2:25 am

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"}
 
User avatar
deadkat
Frequent Visitor
Frequent Visitor
Posts: 57
Joined: Sun Nov 15, 2020 11:14 pm
Location: Alabama, USA

Re: Script doesn't execute (completely) on boot

Fri Dec 31, 2021 4:42 am

This was mentioned here viewtopic.php?t=107927

Who is online

Users browsing this forum: No registered users and 16 guests