Community discussions

MikroTik App
 
texmeshtexas
Member Candidate
Member Candidate
Topic Author
Posts: 151
Joined: Sat Oct 11, 2008 11:17 pm

DHCP server script Internal Global variables

Tue Apr 20, 2021 8:15 pm

Has anyone used the built in variable names in the DHCP Server script?

lease-script (string; Default: "")
Script that will be executed after lease is assigned or de-assigned. Internal "global" variables that can be used in the script:
leaseBound - set to "1" if bound, otherwise set to "0"
leaseServerName - dhcp server name
leaseActMAC - active mac address
leaseActIP - active IP address
lease-hostname - client hostname
lease-options - array of received options

Using leaseActMac and leaseActIP works just fine but
Trying to use lease-hostname. the "-" in the variable name is not agreeing with the script.
Tried using leaseHostname to follow the convention of the other variable names but does not work
 
msatter
Forum Guru
Forum Guru
Posts: 2912
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: DHCP server script Internal Global variables

Wed Apr 21, 2021 1:55 am

Valid characters in variable names are letters and digits. If variable name contains any other character, then variable name should be put in double quotes. Example:
#valid variable name
:local myVar;  
#invalid variable name
:local my-var; 
#valid because double quoted
:global "my-var"; 
https://wiki.mikrotik.com/wiki/Manual:S ... #Variables
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: DHCP server script Internal Global variables

Wed Apr 21, 2021 5:46 pm

Has anyone used the built in variable names in the DHCP Server script?

lease-script (string; Default: "")
Script that will be executed after lease is assigned or de-assigned. Internal "global" variables that can be used in the script:
leaseBound - set to "1" if bound, otherwise set to "0"
leaseServerName - dhcp server name
leaseActMAC - active mac address
leaseActIP - active IP address
lease-hostname - client hostname
lease-options - array of received options

Using leaseActMac and leaseActIP works just fine but
Trying to use lease-hostname. the "-" in the variable name is not agreeing with the script.
Tried using leaseHostname to follow the convention of the other variable names but does not work

simply: use $"lease-hostname"
:if ($leaseBound = "1") do={
 :log info ($"lease-hostname"." request an IP")
} else={
 :log info ($"lease-hostname"." release the IP")
}

Who is online

Users browsing this forum: Bing [Bot], GoogleOther [Bot], grayfoxbsd, MarkusT, Question and 157 guests