Community discussions

MikroTik App
 
User avatar
Buford
just joined
Topic Author
Posts: 20
Joined: Tue Aug 29, 2017 4:09 am
Location: Philippines

Running PoE Script after Reboot

Mon Oct 17, 2022 4:42 am

Hello there!

Based on various forum topics I've read, I have created scheduled scripts that will turn ON and OFF PoE interfaces. But then I noticed that the PoE devices do not turn ON once the switch is rebooted at a time that is after the script schedules.
I am new to using scripts in MikroTik so I do not know if this will work. Your input is highly appreciated.
I have created the following scheduled script below hoping that it will run every time the switch is freshly rebooted.
Hoping to hear from you all...

/system scheduler
add interval=1d name=Activate_PoE_After_Reboot on-event=":local time [/system clock get time]\r\n:if (\$time <= \"6:30:00\" || \$time = \"18:30:00\") do={/interface ethernet poe set 3,4,5,6 poe-out=auto-on;}" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-time=startup
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Running PoE Script after Reboot

Mon Oct 17, 2022 5:17 am

critical 1: hardware undefined
critical 2: routeros version undefined
critical 3: add :delay 20s on top when you do something on startup, for leave the time to load all drivers
error 1: if start-time=startup, interval must be 00:00:00 (†)
error 2: do not compare time to string, and write time on correct way: (($time <= [:totime "06:30:00"]) || ($time >= [:totime "18:30:00"]))
error 3, do not use temporary "print" id (3,4,5,6) to define the interfaces, but the interface names, like: set [find where name~"(ether4|ether5|ether6|ether7)"]
warning 1: the ; is useless if you do not need more commands on one unique line

(†): if you need something that check what time is it and act accordingly, disabling something from 18:31 to 06:29, schedule the script every 1 minutes instead, and also on startup (after 1 min) do it's job.
 
User avatar
Buford
just joined
Topic Author
Posts: 20
Joined: Tue Aug 29, 2017 4:09 am
Location: Philippines

Re: Running PoE Script after Reboot

Mon Oct 17, 2022 7:20 am

Thank you rextended for replying!

Below are details of my switch and all my scheduled scripts with all the edits you have provided. I tried it and it works!
Thank you so much for your help.
# oct/17/2022 12:13:11 by RouterOS 7.3.1
# model = CRS328-24P-4S+
/system scheduler
add interval=1w name=Reboot on-event="system reboot" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=oct/17/2022 start-time=00:01:00
add interval=1d name=PowerOff_cAPs on-event="/interface ethernet poe set [find where name~\"(ether3|ether4|ether5|ether6)\"] poe-out=off; " policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=oct/13/2022 start-time=18:30:00
add interval=1d name=PowerOn_cAPs on-event="/interface ethernet poe set [find where name~\"(ether3|ether4|ether5|ether6)\"] poe-out=auto-on; " policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=oct/13/2022 start-time=06:30:00
add name=Activate_PoE_After_Reboot on-event=":delay 20s\r\n:local time [/system clock get time]\r\n:if ((\$time <= [:to time \"6:30:00\"]) || (\$time >= [:totime \"18:30:00\"]) do={/interface ethernet poe set [find where name~\"(ether3|ether4|ether5|ether6)\"] poe-out=auto-on}" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-time=startup
Last edited by Buford on Tue Oct 18, 2022 2:45 am, edited 1 time in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Running PoE Script after Reboot  [SOLVED]

Mon Oct 17, 2022 2:39 pm

if you export the script is hard to read, better use winbox


Activate_PoE_After_Reboot
:delay 20s

:local time [/system clock get time]

/interface ethernet poe
:if ( ($time <= [:totime "06:30:00"]) || ($time >= [:totime "18:30:00"]) ) do={
    set [find where name~"(ether3|ether4|ether5|ether6)"] poe-out=off
} else={
    set [find where name~"(ether3|ether4|ether5|ether6)"] poe-out=auto-on
}

Notice:
On cold boot the RouterOS do not have the time set, and you must increase ":delay 20s" to the total time the RouterOS need to go on Internet and sync the time.
On reboot RouterOS keep the time and his problem do not happen.


On PowerOff_cAPs and PowerOn_cAPs you do not need nothing more than on/off, because already the scheduler do it at right time:

PowerOff_cAPs
/interface ethernet poe
set [find where name~"(ether3|ether4|ether5|ether6)"] poe-out=off

PowerOn_cAPs
/interface ethernet poe
set [find where name~"(ether3|ether4|ether5|ether6)"] poe-out=auto-on
 
User avatar
Buford
just joined
Topic Author
Posts: 20
Joined: Tue Aug 29, 2017 4:09 am
Location: Philippines

Re: Running PoE Script after Reboot

Tue Oct 18, 2022 2:47 am

Thank you so much rextended!
Everything is working now and I am getting a better understanding on how the script does its job.

I have increased the delay to 60s as per your suggestion.

Cheers! :D

Who is online

Users browsing this forum: Rhydu and 15 guests