Community discussions

MikroTik App
 
HaPe
Member Candidate
Member Candidate
Topic Author
Posts: 239
Joined: Fri Feb 10, 2012 10:24 pm
Location: Poland

Get last entry from RoS

Wed May 13, 2020 4:46 pm

Hello,
I can list for example entries from firewall:
[hape@router1] /ip firewall nat> print 
Flags: X - disabled, I - invalid, D - dynamic 
 0    ;;; NAT 1
      chain=srcnat action=masquerade src-address-list=VPN_POOL dst-address-list=PEERING_1 log=no log-prefix="" 

 1    ;;; NAT 2
      chain=srcnat action=masquerade src-address-list=VPN_POOL dst-address-list=PEERING_1 log=no log-prefix="" 

 2    ;;; NAT 2
      chain=srcnat action=masquerade src-address-list=VPN_POOL dst-address-list=PEERING_1 log=no log-prefix=""
But how to get/print last value with id 2?
 
msatter
Forum Guru
Forum Guru
Posts: 2912
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: Get last entry from RoS

Wed May 13, 2020 5:31 pm

:foreach ID in=[/ip fire nat find comment="NAT 2"] do={:set $lastLine $ID}; print where .id=$lastLine;
 
User avatar
mutluit
Forum Veteran
Forum Veteran
Posts: 821
Joined: Wed Mar 25, 2020 4:04 am

Re: Get last entry from RoS

Wed May 13, 2020 6:59 pm

Hi @msatter, @HaPe/OP, anybody:

I've created this script and installed it under /system/script under the name myTest1,
and I do run it with "run myTest1". But it prints only the first of the :put's (ie. the interfaces, but not their IPs), whereas
if I execute the two foreach blocks individually in the shell prompt then both do print correct results (here ether2 and ether24 do have IPs).

Ie. I think there is a bug in the script executor (what a name! :-)), or its parser.
Tested in 7.0beta5 on CRS326.
[admin2@MikroTik] /system/script> print 
Flags: I - invalid 
 0   name="myTest1" owner="admin2" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon dont-require-permissions=no last-started=may/09/2020 10:33:54 run-count=4 
     source=
       # myTest1
       
       :foreach i in=[/interface find type=ether ] do={
         :put ("+-- " . [/interface get $i name]);
         :foreach j in=[/ip address find interface=$i] do={
           :put ("|  `--" . [/ip address get $j address]);
         }
       }

Who is online

Users browsing this forum: No registered users and 15 guests