Community discussions

MikroTik App
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

JOBS section of the script list

Wed Jun 29, 2022 10:53 pm

I have this script where all the "GLOBAL VARIABLES" are already declared in other scripts, therefore I consider that I should not declare it again, which I do not understand because the script is executed only once or twice and it no longer appears in the JOBS section, what would be wrong? Thanks for teaching.

:delay 15m

:global stopRouterRun 
:global now
     :local filenameIP "iphistory.txt"

:do {

    /file
    :if ([:len [find where name="flash" and type="disk"]] = 1) do={:set filenameIP "flash/$filenameIP"}
    :if ([:len [find where name=$filenameIP]] = 0) do={print file="$filenameIP"; :delay 5s; set $filenameIP contents=""}
:global currentIP
    :local newIP [/ip address get [find interface="ETHERT 1"] address]
    :set newIP [:pick $newIP 0 [:find $newIP "/" -1]]
    :if ($newIP != $currentIP) do={
    /file
    :delay 5s
    :local filecontent [get $filenameIP contents]
    :local newfilecontent "********************************************************************\r\nNEW IP:     $newIP\t$now\r\n$filecontent"    
    set $filenameIP contents=$newfilecontent
    :set currentIP $newIP
}

    :delay 10s
} while=(!$stopRouterRun)


EL DONCITO.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: JOBS section of the script list

Wed Jun 29, 2022 11:29 pm

Is not exactly like the original...
viewtopic.php?p=924069#p924069

What problem you have to leave it as is, and on other script use other variable names?
The only global variable used on original script is storedIP for compare previous IP with the actual, all other can be perfectly local only....

Also scheduler exist, is not needed to make for each script a permanent job on loop...
Scheduler is invented exactly to run scripts on intervals....

Also if the job on loop is interrupted, for example because the address is missing on that moment, or interface is not ready, you must manually restart...
Instead with scheduler, every x time the run of the script is retried, an probably work near everytime.
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: JOBS section of the script list

Thu Jun 30, 2022 12:05 am

Ok rextendex, but doesn't that make the routerboard have more consumption in the CPU or memory?



EL DONCITO.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: JOBS section of the script list

Thu Jun 30, 2022 12:09 am

Approx "9+8+32 Bytes" ?

Consume more precious CPU resources various processes in loops...
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: JOBS section of the script list

Thu Jun 30, 2022 12:23 am

Just "invented" this for test the memory occupied from 10.000 global variables

terminal code

[rex@net] /system resource> :put [get free-memory]                                                             
213348352
[rex@net] /system resource> :for x from=1 to=10000 step=1 do={ [:parse ":global abcdefgh$x 255.255.255.255/32"] }
[rex@net] /system resource> :put [get free-memory]                                                               
212856832
[rex@net] /system resource> 
10.000 variables with name from 9 characters to 13 (abcdefgh1, abcdefgh2..... abcdefgh9999, abcdefgh10000) and "fake" IP-prefix as internal value
use 491520 Bytes, near 50 Bytes for each variable...
and I deduce than a device with 256.0MiB can store 4.000.000 of global variables before start to be a problem......
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: JOBS section of the script list

Thu Jun 30, 2022 10:20 pm

I did what you told me friend REXTENDED, and it didn't work, when the IP changes 2 times, the script stops working, is that because?
Because what I want to do is that every time the routerboard is restarted, the script starts, it takes 15 min, after those 15 min the script is executed and it is running every 10 seconds.





EL DONCITO.

Who is online

Users browsing this forum: JDF and 24 guests