mirror of
https://github.com/eworm-de/routeros-scripts
synced 2024-05-14 08:04:19 +00:00
9c9fb46e4a
Every instance of the scripts does all the work. If one script is running and a second script is waiting we do not have to start a third one.
38 lines
1.4 KiB
Text
38 lines
1.4 KiB
Text
#!rsc by RouterOS
|
|
# RouterOS script: lease-script
|
|
# Copyright (c) 2013-2021 Christian Hesse <mail@eworm.de>
|
|
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
|
|
#
|
|
# run scripts on DHCP lease
|
|
# https://git.eworm.de/cgit/routeros-scripts/about/doc/lease-script.md
|
|
|
|
:local 0 "lease-script";
|
|
:global GlobalFunctionsReady;
|
|
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
|
|
|
|
:global IfThenElse;
|
|
:global LogPrintExit2;
|
|
|
|
:if ([ :typeof $leaseActIP ] = "nothing" || \
|
|
[ :typeof $leaseActMAC ] = "nothing" || \
|
|
[ :typeof $leaseServerName ] = "nothing" || \
|
|
[ :typeof $leaseBound ] = "nothing") do={
|
|
$LogPrintExit2 error $0 ("This script is supposed to run from ip dhcp-server.") true;
|
|
}
|
|
|
|
:local State ([ $IfThenElse ($leaseBound = 0) "de" "" ] . "assign");
|
|
|
|
$LogPrintExit2 debug $0 ("DHCP Server " . $leaseServerName . " " . \
|
|
$State . "ed lease " . $leaseActIP . " to " . $leaseActMAC) false;
|
|
|
|
:foreach Script in=[ / system script find where source~("\n# provides: lease-script " . $State . "\n") ] do={
|
|
:local ScriptName [ / system script get $Script name ];
|
|
:if ([ :len [ / system script job find where script=$ScriptName ] ] < 2) do={
|
|
:do {
|
|
$LogPrintExit2 debug $0 ("Running script: " . $ScriptName) false;
|
|
/ system script run $Script;
|
|
} on-error={
|
|
$LogPrintExit2 warning $0 ("Running script '" . $ScriptName . "' failed!") false;
|
|
}
|
|
}
|
|
}
|