Community discussions

MikroTik App
 
Cobusbu
newbie
Topic Author
Posts: 43
Joined: Fri Jan 04, 2008 9:20 am
Location: Cape Town, South Africa

How can I access a global variable on another router?

Sat Dec 06, 2008 1:22 pm

Hi

Is it possible for a script on one router to access a global variable on another router?

What would the command be in order to do this?

Any help will be appreciated.
 
User avatar
Letni
Member
Member
Posts: 376
Joined: Tue Dec 05, 2006 5:16 am
Location: South Carolina

Re: How can I access a global variable on another router?

Sat Dec 06, 2008 6:42 pm

Simple answer is no.

Tedious answer is to export out your variable to a file on Router1.
Then on Router2 fetch the file and import it to load your variable.

There are many drawbacks to this method.
But it gets some information from Rtr1 to Rtr2

-Louis
 
Cobusbu
newbie
Topic Author
Posts: 43
Joined: Fri Jan 04, 2008 9:20 am
Location: Cape Town, South Africa

Re: How can I access a global variable on another router?

Sun Dec 07, 2008 8:31 am

Thanks Letni

I will investigate this method.
 
TomInIowa
just joined
Posts: 14
Joined: Thu Nov 13, 2008 3:38 am

Re: How can I access a global variable on another router?

Mon Dec 08, 2008 8:00 am

"
Tedious answer is to export out your variable to a file on Router1.
Then on Router2 fetch the file and import it to load your variable."

I have been reading the forum looking for how to do the above!!
How do you export one or two variables to a file?
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7198
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: How can I access a global variable on another router?

Tue Dec 09, 2008 3:38 pm

:global myVar aaa;
/file print file=vars
/file set vars.txt contents="myVar $myVar"
on another router,
/tool fetch address=x.x.x.x src-path="vars.txt" mode=ftp user=admin password="";
:local content [ /file get varst.txt contents ];
.. now you can parse contents to retreive information 
 
TomInIowa
just joined
Posts: 14
Joined: Thu Nov 13, 2008 3:38 am

Re: How can I access a global variable on another router?

Tue Dec 09, 2008 6:20 pm

thank you ...
 
TomInIowa
just joined
Posts: 14
Joined: Thu Nov 13, 2008 3:38 am

Re: How can I access a global variable on another router?

Wed Dec 10, 2008 5:09 pm

what I want to do ...
keep track of how much data is downloaded/uploaded per hour.
I have a script now that gets the information from the registration table and writes it a file.

:local debug 0
:local s1 " "
:local s2 " "
:local d1 " "
:local byte1 " "
:local backupfile ( [/system clock get date] . "---". [/system clock get time])
:foreach i in=[/interface wireless registration-table find] do= {
:local cbyte [/interface wireless registration-table get $i bytes]
# split the data bytes into two parts ... downloaded and uploaded
:local pos1 [:find $cbyte "," -1]
:local byte1 [:pick $cbyte 0 $pos1]
:set s1 ( $byte1 )


:set pos1 ( pos1 +1 )
:local s2 [:pick $cbyte $pos1 20]


:set s1 ( s1 . $s2 . " " . $backupfile )
:local content [ /file get data_used.txt contents]
:set content ( content . " \r\n" . $s1 )
/file set data_used.txt contents=$content

# /interface wireless registration-table reset $i

}


this is working for me ....
Now my problem is it quits working when the file size is 4026 B.
Question: is there a way to "APPEND" the new information to the file ... as opposed to reading the file into one variable and then rewriting the entire file?
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: How can I access a global variable on another router?

Wed Dec 10, 2008 6:19 pm

The max file size is 4095 bytes. At the present time, you cannot read or write files larger than that. I have put in a request to read larger files, and omega-00 has requested the write part. We are still waiting.
 
Cobusbu
newbie
Topic Author
Posts: 43
Joined: Fri Jan 04, 2008 9:20 am
Location: Cape Town, South Africa

Re: How can I access a global variable on another router?

Wed Dec 10, 2008 6:25 pm

Thanks mrz

The global variable is $bytestotal. I want the router to extract this variable from another router every 15 minutes. As soon as it exceeds 100MB it must disconnect the user's PPPoE session.