How to get only what i need?

Hello,

I made a script in bash in a Linux box that will ssh the mikrotik and get the “/ip dhcp-server leases”

Right now i am using this in the script to get the list:

ssh user@mikroti.ip.address "/ip dhcp-server lease print terse" > /home/user/dhcp-list.txt

And when i get all data, i process it with awk and sed to get only IP address and Host name leased.. but in some lines its different and where the columnt where the Host-name is, i get the active server or the mac address and i dont need it.

Bottom line, its there a command that only shows what i need when i print? ie.
/ip dhcp-server lease print [host-name, ip-address] or something.?

thanks in advance.

JB

No one? :frowning:

maybe this can help you

ssh admin@ip.mikrotik ':foreach i in=[ip dhcp-server lease find ] do={; local ip [ip dhcp-server lease get value-name=address $i]; local hostname [ip dhcp-server lease get value-name=host-name $i]; put "$ip $hostname";}' > leases.txt

Gracias!! That’s what i needed! I will give it a read this days to do some scripting in Mikrotik, right know i only use Bash to do stuff in the MT but eventually i think could be more handy scripting directly in the device.

Thanks again :wink:

Theres some karma for you :slight_smile:

Solved

Solved. Thank you