Reiney
August 8, 2012, 5:40pm
1
Hi All,
I’m creating a script to reset selected PPPoE connections.
I am trying to read the internal menu ID number (ie. stuff it in
to a variable of the correct type). A “put” of the whole string
for a selected connection shows “.id” as the variable name but
I can’t seem to use that. Here’s my test script so far …
resets selected cpe interface once per day at 7:00am
{
:local cpename “mimosa”;
:local ifname (“<” . “pppoe-” . $cpename . “>”);
:put $cpename;
:put $ifname;
:local ifstr [/interface get [find name=$ifname]];
:local idstr [pick $ifstr 0];
:put $idstr;
}
---- output ----
mimosa
.id=*104c0
Thanks in advance!
~Reiney
$ifstr wil contain an array of ids, $idstr will hold the first entry of these
They can be used either way:
/interface set $ifstr disabled=yes
/interface set $idstr disabled=yes
or
/interface remove $ifstr
/interface remove $idstr
In your current example it will be the same (since there at most can be one interface with a specific name)
Reiney
August 9, 2012, 6:33am
3
Thanks for the reply. Unfortunately, none of the examples you
mention seem to work. The interfaces I am trying to remove have been
dynamically created via PPP. What does work is to do something
like “/ppp active remove xx” where “xx” is the “item number” you see
when doing a /ppp active print.
It is this item number (also known as Internal ID ??) that I need to parse
out of the connection info string.
~Reiney
Ah, I missd the problem
:local ifstr [/interface get [find name=$ifname]];
should be
:local ifstr [/interface find name=$ifname];
Reiney
August 9, 2012, 7:02pm
5
That really doesn’t work either …
Here’s a “fresh” example:
The goal: Supply a connection name (“main-2” in this example), and issue a “/ppp active remove xx” command to
drop the specified connection.
This is what /ppp active print returns:
[admin@rb0-dj2] /system script> /ppp active print
Flags: R - radius
NAME SERVICE CALLER-ID ADDRESS UPTIME ENCODING
0 R general-g… pppoe 00:27:22:72:B6:5D 63.233.220.144 1w5d6…
1 R general-g… pppoe 00:25:9C:5A:2E:F2 63.233.220.233 1w2d1…
|
|
|
22 R santo-1 pppoe 00:60:B3:45:31:E0 63.233.220.158 1d19h…
23 R main-2 pppoe 00:0D:93:01:B6:9F 63.229.162.175 1d19h…
24 R cerro-chato pppoe 00:27:22:22:5F:29 63.233.220.181 1d19h…
There’s our example; it is “item number” 23.
Here’s a fresh example of the script. I put “address” in there as a test:
resets selected cpe interface once per day at 7:00am
{
:local cpename “main-2”;
:local ifstr [/ppp active get [find name=$cpename] address ];
:put $cpename;
:put $ifstr;
}
… and I get this:
[admin@rb0-dj2] /system script> run cpe_reset
main-2
63.229.162.175
If I substitue “uptime” for “address”, I get this:
main-2
1d19:32:10
So, how do I get the Item Number? It is shown in the command output as a “#”.
If I run the script without specifying the variable that I want, I get this:
main-2
.id=*104a0;name=main-2;service=pppoe;caller-id=00:0D:93:01:B6:9F;address=63.229.162.175;uptime=1d19:33:08;encoding=;session-id=2172704812;limit-bytes-in=0;limit-bytes-out=0;radius=false
The first field looks an awful lot like some sort of Menu/ID number and it’s in hex; But how do I pull that out???
Thanks again!
These all do the same:
/ppp active remove [find name="main-2]
{
:local cpename "main-2";
/ppp active remove [find name=$cpename]
}
{
:local cpename "main-2";
:local o [/ppp active find name=$cpename]
/ppp active remove $o
}
/ppp active {
:local cpename "main-2";
:local o [find name=$cpename]
remove $o
}
Reiney
August 11, 2012, 3:50am
7
Ah … Now I get it!
Thanks so much for the great examples,
~Reiney