Community discussions

MikroTik App
 
User avatar
CyB3RMX
Member Candidate
Member Candidate
Topic Author
Posts: 148
Joined: Thu May 26, 2011 7:08 am

How to get only what i need?

Fri May 02, 2014 5:50 pm

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
 
User avatar
CyB3RMX
Member Candidate
Member Candidate
Topic Author
Posts: 148
Joined: Thu May 26, 2011 7:08 am

Re: How to get only what i need?

Fri May 02, 2014 8:31 pm

No one? :(
 
User avatar
c0d3rSh3ll
Long time Member
Long time Member
Posts: 557
Joined: Mon Jul 25, 2011 9:42 pm
Location: [admin@Chile] >

Re: How to get only what i need?

Fri May 02, 2014 9:56 pm

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
 
User avatar
CyB3RMX
Member Candidate
Member Candidate
Topic Author
Posts: 148
Joined: Thu May 26, 2011 7:08 am

Re: How to get only what i need?

Sat May 03, 2014 1:40 am

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 ;)

Theres some karma for you :)
 
hmrka139
just joined
Posts: 22
Joined: Tue Jul 21, 2009 1:52 pm

Re: How to get only what i need?

Mon May 05, 2014 2:28 pm

Solved
Last edited by hmrka139 on Fri May 09, 2014 11:12 am, edited 1 time in total.
 
hmrka139
just joined
Posts: 22
Joined: Tue Jul 21, 2009 1:52 pm

Re: How to get only what i need?

Tue May 06, 2014 2:08 pm

Solved. Thank you

Who is online

Users browsing this forum: nickcarr and 25 guests