Page 1 of 1

How can I access a global variable on another router?

Posted: Sat Dec 06, 2008 1:22 pm
by Cobusbu
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.

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

Posted: Sat Dec 06, 2008 6:42 pm
by Letni
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

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

Posted: Sun Dec 07, 2008 8:31 am
by Cobusbu
Thanks Letni

I will investigate this method.

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

Posted: Mon Dec 08, 2008 8:00 am
by TomInIowa
"
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?

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

Posted: Tue Dec 09, 2008 3:38 pm
by mrz
: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 

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

Posted: Tue Dec 09, 2008 6:20 pm
by TomInIowa
thank you ...

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

Posted: Wed Dec 10, 2008 5:09 pm
by TomInIowa
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?

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

Posted: Wed Dec 10, 2008 6:19 pm
by SurferTim
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.

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

Posted: Wed Dec 10, 2008 6:25 pm
by Cobusbu
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.