Enable a rule just for specific time

How can I set a timer to trigger a firewall rule enabling and automatically disabling after X minutes ?
Not a scheduled rule (made by schedule or rule “time” option) , a “one shot” rule to be triggered when needed.

Thanks

You can do that in scheduler with one activating the rule and a second onedisabling it again.
In a scipt you can also put a :delay 2m between to script lines.

Thanks,
What about to simply enable the rule and disable it after x minutes ?

/ip firewall filter enable <rule>
delay 3600;
/ip firewall filter disable <rule>

any issue in leaving script hung for a long time ?

Obvioulsy it will consume some memory and CPU…

/system scheduler
add interval=31s name=schedule1 on-event=“/ip firewall filter disable 2” policy=
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-time=startup

add interval=14s name=schedule2 on-event=“/ip firewall filter enable 2” policy=
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-time=startup




there you have the two scripts, you just have to adapt it to your demands, I hope they serve you.

/system scheduler
add disabled=yes interval=30s name=“Scheduler10” on-event=
“/ip firewall filter disable 2\r
\ndelay 10;\r
\n/ip firewall filter enable 2” policy=
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=dec/01/2018
start-time=00:00:00

there you have another script, you just have to adapt it to your demands, I hope it works for you

I think now you just inform the rb to do some thing and take a rest for some second and then do other things so it will not spend cpu and ram
this is my opinion