Community discussions

MikroTik App
 
mlu1
just joined
Topic Author
Posts: 2
Joined: Tue Dec 31, 2019 11:12 am

Global environment variable is disappearing after logout

Wed Jan 01, 2020 11:15 pm

Hello,

I've created a simple script which is storing a value inside a global environment variable. It should be part of a bigger script but for simplification i reduced it to the essential.
> /system script print 
Flags: I - invalid 
 0   name="testscript" owner="admin" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon dont-require-permissions=no 
     last-started=jan/01/2020 22:01:58 run-count=1 source=
       :global oldprefix;
       :local curprefix;
       
       :set curprefix [/ipv6 pool get telekom-pd prefix]
       :set oldprefix $curprefix
When I run the script, I can see that the variable is set properly.
> /system script run 0
> /system script environment print 
 # NAME               VALUE                                                                                                                                   
 0 oldprefix          2003:de:ffff:ff00::/56                                                                                                                  
When I log back in after some time, the variable does not appear anymore, neither on console nor in the webinterface. The table is empty now. When I stay logged in, the variable doesn't seem to disappear. But sometimes I see that the variable still exists after logging out and logging back in.
> /system script environment print 
 # NAME               VALUE                                                                                                                                   
Aren't the global variables persistent? If not, what is the best practice to store values for later usage in a periodic run script
 
User avatar
diamuxin
Member
Member
Posts: 317
Joined: Thu Sep 09, 2021 5:46 pm
Location: Alhambra's City

Re: Global environment variable is disappearing after logout

Wed Oct 12, 2022 7:31 pm

Hi @mlu1,

Were you able to solve this problem? I have a relative who is going through the same problem.

Someone has been the same? any advice?

Thanks & BR.
 
gojay68706
just joined
Posts: 2
Joined: Fri Aug 26, 2022 6:12 am

Re: Global environment variable is disappearing after logout

Mon Oct 24, 2022 6:16 am

I have the same issue with dhcpv6 client script. I set the old prefix to a global variable, but the variable and run count are disappearing after some times.
 
Puffer
just joined
Posts: 24
Joined: Mon Mar 08, 2010 2:09 pm

Re: Global environment variable is disappearing after logout

Tue Apr 18, 2023 9:32 pm

Hi Folks, anybody having a similar issue. I'm also creating a global variable from the DHCP script. It also disappears after a period, sometimes minutes, sometimes several hours.
I created a similar variable with a normal script and this variable too disappears and more interestingly the run count on the script also clears to 0. Almost as if a rollback occurs.
Would love to know what is causing this.
 
K0NCTANT1N
newbie
Posts: 47
Joined: Thu Jun 08, 2023 9:35 pm

Re: Global environment variable is disappearing after logout

Sun Aug 13, 2023 6:42 pm

Anyone found a solution? I have a similar problem here: viewtopic.php?t=184618
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3169
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Global environment variable is disappearing after logout

Sun Aug 13, 2023 7:01 pm

No idea why they'd disappear. Maybe the dhcp process restarts and it loses them, really dunno...

One idea is create them in schedule script that runs at startup, so the dhcp script never creates a global.

e.g. in scheduler
:global oldprefix
:set oldprefix 0.0.0.0/0
:global newprefix
:set newprefix 0.0.0.0/0
I avoid assigning a global on the same line, and always set them – shouldn't be necessary but seems safer.
 
msatter
Forum Guru
Forum Guru
Posts: 2897
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: Global environment variable is disappearing after logout

Mon Aug 14, 2023 12:20 am

I remembered this from the Wiki / manual:
GlobalWarning.JPG
You do not have the required permissions to view the files attached to this post.
 
K0NCTANT1N
newbie
Posts: 47
Joined: Thu Jun 08, 2023 9:35 pm

Re: Global environment variable is disappearing after logout

Fri Aug 18, 2023 6:04 pm

Anyone found a solution? I have a similar problem here: viewtopic.php?t=184618
There is a solution
viewtopic.php?p=1019883

Who is online

Users browsing this forum: ko00000000001 and 17 guests