mode-button-scheduler: early exit with :exit

This commit is contained in:
Christian Hesse 2026-07-17 10:09:27 +02:00
parent a88eea6e64
commit 363adaaa47
3 changed files with 7 additions and 11 deletions

View file

@ -4,7 +4,7 @@ Mode button with multiple presses
[![GitHub stars](https://img.shields.io/github/stars/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=red)](https://github.com/eworm-de/routeros-scripts/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=green)](https://github.com/eworm-de/routeros-scripts/network)
[![GitHub watchers](https://img.shields.io/github/watchers/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=blue)](https://github.com/eworm-de/routeros-scripts/watchers)
[![required RouterOS version](https://img.shields.io/badge/RouterOS-7.21-yellow?style=flat)](https://mikrotik.com/download/changelogs/)
[![required RouterOS version](https://img.shields.io/badge/RouterOS-7.22-yellow?style=flat)](https://mikrotik.com/download/changelogs/)
[![Telegram group @routeros_scripts](https://img.shields.io/badge/Telegram-%40routeros__scripts-%2326A5E4?logo=telegram&style=flat)](https://t.me/routeros_scripts)
[![donate with PayPal](https://img.shields.io/badge/Like_it%3F-Donate!-orange?logo=githubsponsors&logoColor=orange&style=flat)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A4ZXBD6YS2W8J)

View file

@ -3,13 +3,12 @@
# Copyright (c) 2018-2026 Christian Hesse <mail@eworm.de>
# https://rsc.eworm.de/COPYING.md
#
# requires RouterOS, version=7.21
# requires RouterOS, version=7.22
# requires device-mode, scheduler
#
# act on multiple mode and reset button presses
# https://rsc.eworm.de/doc/mode-button.md
:local ExitOK false;
:onerror Err {
:global GlobalConfigReady; :global GlobalFunctionsReady;
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
@ -39,8 +38,7 @@
:if ([ :len $Scheduler ] = 0) do={
$LogPrint error $ScriptName ("Scheduler does not exist.");
:set ExitOK true;
:error false;
:exit;
}
:local Count ([ :deserialize from=json [ /system/scheduler/get $Scheduler comment ] ]->"count");
@ -50,15 +48,13 @@
:if ([ :len $Code ] = 0) do={
$LogPrint info $ScriptName ("No action defined for " . $Count . " mode-button presses.");
:set ExitOK true;
:error false;
:exit;
}
:if ([ $ValidateSyntax $Code ] = false) do={
$LogPrint warning $ScriptName \
("The code for " . $Count . " mode-button presses failed syntax validation!");
:set ExitOK true;
:error false;
:exit;
}
$LogPrint info $ScriptName ("Acting on " . $Count . " mode-button presses: " . $Code);
@ -80,5 +76,5 @@
("The code for " . $Count . " mode-button presses failed with runtime error: " . $Err);
}
} do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
:global ExitOnError; $ExitOnError [ :jobname ] $Err;
}

View file

@ -3,7 +3,7 @@
# Copyright (c) 2018-2026 Christian Hesse <mail@eworm.de>
# https://rsc.eworm.de/COPYING.md
#
# requires RouterOS, version=7.21
# requires RouterOS, version=7.22
# requires device-mode, scheduler
#
# act on multiple mode and reset button presses