diff --git a/doc/template.md b/doc/template.md new file mode 100644 index 0000000..1e4f9d8 --- /dev/null +++ b/doc/template.md @@ -0,0 +1,48 @@ +# Script name + +[⬅️ Go back to main README](../README.md) + +> ℹ️ **Info**: This script can not be used on its own but requires the base +> installation. See [main README](../README.md) for details. + +## Table of Contents + +- [Script name](#script-name) + - [Table of Contents](#table-of-contents) + - [Description](#description) + - [Requirements and installation](#requirements-and-installation) + - [Configuration](#configuration) + - [Usage and invocation](#usage-and-invocation) + - [See also](#see-also) + +## Description + +Function description of the script and which goal it should achieve. + +## Requirements and installation + +Just install the script: + +```rsc +$ScriptInstallUpdate script-file-name-without-filename-extension "base-url=https://git.s1q.dev/phg/routeros-scripts-custom/raw/branch/main/"; +``` + +## Configuration + +What to configure to run the script + +## Usage and invocation + +How to run the script: + +```rsc +/system/script/run script-file-name-without-filename-extension; +``` + +## See also + +* ... + +--- +[⬅️ Go back to main README](../README.md) +[⬆️ Go back to top](#top) diff --git a/template.rsc.tpl b/template.rsc.tpl index b596501..76e110c 100644 --- a/template.rsc.tpl +++ b/template.rsc.tpl @@ -8,26 +8,26 @@ # # https://git.s1q.dev/phg/routeros-scripts-custom/about/doc/.md -:global GlobalFunctionsReady; -:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } - :local ExitOK false; -:do { +onerror Err { + :global GlobalConfigReady; :global GlobalFunctionsReady; + :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ + do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; :local ScriptName [ :jobname ]; :global LogPrint; - :global ParseKeyValueStore; - :global ScriptLock; + :global ScriptFromTerminal; + :global SendNotification2; - # Local/global script specific variables - - :if ([ $ScriptLock $ScriptName ] = false) do={ - :set ExitOK true; - :error false; + # Log notifications locally, or send them via email/pushover etc. when not run from terminal + # Usually used for important notifications only + :if ([ $ScriptFromTerminal $ScriptName ] = true) do={ + # Add Script from here for running from terminal: + $LogPrint info $ScriptName ("Hello world!"); + } else={ + # Add Script from here for running as scheduled script: + $SendNotification2 ({ origin=$ScriptName; subject="Hello..."; message="... world!" }); } - - # Add Script from here: - -} on-error={ - :global ExitError; $ExitError $ExitOK [ :jobname ]; -} \ No newline at end of file +} do={ + :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +}