Community discussions

MikroTik App
 
tomislav91
Member
Member
Topic Author
Posts: 303
Joined: Fri May 26, 2017 12:47 pm

multiple lines into one

Mon Aug 20, 2018 3:07 pm

How it possible to do it in one line of code in terminal this command i found here on forum
/ip dhcp-server lease {
:foreach i in=[find (!dynamic && status="bound")] do={
:local activeAddress [get $i active-address]
:local activeMacAddress [get $i active-mac-address]
:local hostname [get $i host-name]

:put ($outputContent . "\n" . $activeAddress . "," . $activeMacAddress . "," . $hostname)
}
}
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7054
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: multiple lines into one

Mon Aug 20, 2018 3:17 pm

{ do={ command1; command2; command3; }}
 
User avatar
NathanA
Forum Veteran
Forum Veteran
Posts: 829
Joined: Tue Aug 03, 2004 9:01 am

Re: multiple lines into one

Mon Aug 20, 2018 3:19 pm

Semicolon ;

Put it between any line that does not end in { or before a line that begins with }

EDIT: mrz beat me to it
 
tomislav91
Member
Member
Topic Author
Posts: 303
Joined: Fri May 26, 2017 12:47 pm

Re: multiple lines into one

Mon Aug 20, 2018 3:27 pm

It gives me error. It works directly to mirkotik but from ssh i cant do it.
Does it possible to resolve that issue?
 
User avatar
mkx
Forum Guru
Forum Guru
Posts: 11624
Joined: Thu Mar 03, 2016 10:23 pm

Re: multiple lines into one

Mon Aug 20, 2018 3:33 pm

One-liner
/ip dhcp-server lease { :foreach i in=[find (!dynamic && status="bound")] do={ :local activeAddress [get $i active-address]; :local activeMacAddress [get $i active-mac-address]; :local hostname [get $i host-name]; :put ($outputContent . "\n" . $activeAddress . "," . $activeMacAddress . "," . $hostname) } }
works for me when connecting to RB via ssh.
 
tomislav91
Member
Member
Topic Author
Posts: 303
Joined: Fri May 26, 2017 12:47 pm

Re: multiple lines into one

Mon Aug 20, 2018 3:39 pm

sshpass -p $pass ssh -o $log -n $user@$h -p 4111 /ip dhcp-server lease { :foreach i in=[find (!dynamic && status="bound")] do={ :local activeAddress [get $i active-address]; :local activeMacAddress [get $i active-mac-address]; :local hostname [get $i host-name]; :put ($outputContent . "\n" . $activeAddress . "," . $activeMacAddress . "," . $hostname) } } print file=$n
this is my ssh code...
but throw me error
line 11: syntax error near unexpected token `('
 
sindy
Forum Guru
Forum Guru
Posts: 10206
Joined: Mon Dec 04, 2017 9:19 pm

Re: multiple lines into one

Mon Aug 20, 2018 4:12 pm

That looks to me as an insufficient indication to bash what it should handle and what not..

Try to place the whole command for Mikrotik into quotes and escape the symbols ",$,\ you need to make it to Mikrotik:

sshpass -p $pass ssh -o $log -n $user@$h -p 4111 "/ip dhcp-server lease { :foreach i in=[find (!dynamic && status=\"bound\")] do={ :local activeAddress [get \$i active-address]; :local activeMacAddress [get \$i active-mac-address]; :local hostname [get \$i host-name]; :put (\$outputContent . \"\\n\" . \$activeAddress . \",\" . \$activeMacAddress . \",\" . \$hostname) } } print file=\$n"

Hint: to make sure it works properly, start by using echo instead of sshpass ... -p 4111 and fine-tune the escaping until the output is exactly what you want the Mikrotik to get.
 
User avatar
mkx
Forum Guru
Forum Guru
Posts: 11624
Joined: Thu Mar 03, 2016 10:23 pm

Re: multiple lines into one

Mon Aug 20, 2018 6:22 pm

Try to place the whole command for Mikrotik into quotes....
Actually it's better to put everything into single quotes. In bash both types of quotes mean "treat this as single argument", the big difference is that bash tries to substitute plenty of things within double-quoted text while it will pass verbatim whatever single-quoted.

Example:
N=4; echo "$N"
will produce line containing simple "4" while
N=4; echo '$N'
will produce line
$N
 
tomislav91
Member
Member
Topic Author
Posts: 303
Joined: Fri May 26, 2017 12:47 pm

Re: multiple lines into one

Mon Aug 20, 2018 7:11 pm

does it possible from that script to get only ip addresses with hostname i define?
 
sindy
Forum Guru
Forum Guru
Posts: 10206
Joined: Mon Dec 04, 2017 9:19 pm

Re: multiple lines into one

Mon Aug 20, 2018 7:16 pm

Sorry, can you use another wording? It is not clear to me what you need.
 
tomislav91
Member
Member
Topic Author
Posts: 303
Joined: Fri May 26, 2017 12:47 pm

Re: multiple lines into one

Mon Aug 20, 2018 7:22 pm

That looks to me as an insufficient indication to bash what it should handle and what not..

Try to place the whole command for Mikrotik into quotes and escape the symbols ",$,\ you need to make it to Mikrotik:

sshpass -p $pass ssh -o $log -n $user@$h -p 4111 "/ip dhcp-server lease { :foreach i in=[find (!dynamic && status=\"bound\")] do={ :local activeAddress [get \$i active-address]; :local activeMacAddress [get \$i active-mac-address]; :local hostname [get \$i host-name]; :put (\$outputContent . \"\\n\" . \$activeAddress . \",\" . \$activeMacAddress . \",\" . \$hostname) } } print file=\$n"

Hint: to make sure it works properly, start by using echo instead of sshpass ... -p 4111 and fine-tune the escaping until the output is exactly what you want the Mikrotik to get.
some brackets are not good closed, or I am wrong. It returns me error with brackets..
 
tomislav91
Member
Member
Topic Author
Posts: 303
Joined: Fri May 26, 2017 12:47 pm

Re: multiple lines into one

Mon Aug 20, 2018 7:24 pm

Sorry, can you use another wording? It is not clear to me what you need.
Ok, look, i have my dhcp lease on several computers.
I want to get Ip address of hostname PC.
SO i wrote a bash script that connect via ssh to mikrotik and run a terminal command.
Problem is that I dont know how to get IP address of dhcp lease address with hostname=PC.
 
tomislav91
Member
Member
Topic Author
Posts: 303
Joined: Fri May 26, 2017 12:47 pm

Re: multiple lines into one

Mon Aug 20, 2018 8:02 pm

I got via

ip dhcp-server lease print where host-name="pc"

but you help me how to get only Ip address without unnecessary information from result of command?
 
sindy
Forum Guru
Forum Guru
Posts: 10206
Joined: Mon Dec 04, 2017 9:19 pm

Re: multiple lines into one

Mon Aug 20, 2018 8:09 pm

put [ip dhcp-server lease get [find hostname="pc"] address]
 
tomislav91
Member
Member
Topic Author
Posts: 303
Joined: Fri May 26, 2017 12:47 pm

Re: multiple lines into one

Mon Aug 20, 2018 8:23 pm

it throws me "no such item"
 
sindy
Forum Guru
Forum Guru
Posts: 10206
Joined: Mon Dec 04, 2017 9:19 pm

Re: multiple lines into one

Mon Aug 20, 2018 9:30 pm

Because a dash was missing in what I wrote. Now I got home and tried using the Tab button:
[me@MyTik] > put [ip dhcp-server lease get [find host-name=my-HP] address]
192.168.88.254
 
tomislav91
Member
Member
Topic Author
Posts: 303
Joined: Fri May 26, 2017 12:47 pm

Re: multiple lines into one

Mon Aug 20, 2018 10:05 pm

Because a dash was missing in what I wrote. Now I got home and tried using the Tab button:
[me@MyTik] > put [ip dhcp-server lease get [find host-name=my-HP] address]
192.168.88.254
thanks man! It works now.
Only last problem,
i must put that into file.
sshpass -p $pass ssh -o $log -n $user@$h -p 4111:global n [ip dhcp-server lease get [find host-name=PC] address];
This thow me no such file..BUt problem is that I need to put it into file...I need file with some name to store this results..
 
sindy
Forum Guru
Forum Guru
Posts: 10206
Joined: Mon Dec 04, 2017 9:19 pm

Re: multiple lines into one

Mon Aug 20, 2018 11:13 pm

I don't know how to create an empty file, but you can create a non-empty file using e.g. /ip address print file=myfile and then replace its contents:
:file set myfile.txt contents=[ip dhcp-server lease get [find host-name=my-HP] address]

But I'm not sure why would you want to save a single value into a file and then download that file using ftp, as if you put it in the command line sent using ssh, the ssh returns that output it to the linux machine:
me@MyLinux:~$ ssh me@192.168.0.1 'put [/ip dhcp-server lease get [find mac-address=00:A3:81:4C:48:42] address]'
192.168.0.25
Or
me@MyLinux:~$ a=$(ssh me@192.168.0.1 'put [/ip dhcp-server lease get [find mac-address=00:A3:81:4C:48:42] address]')
me@MyLinux:~$ echo $a
192.168.0.25
 
tomislav91
Member
Member
Topic Author
Posts: 303
Joined: Fri May 26, 2017 12:47 pm

Re: multiple lines into one

Mon Aug 20, 2018 11:30 pm

thanks for reply.
Problem lies somewhere alse abvious.

When sshpass this command
ip dhcp-server lease print file=$n
my script execute without problem.
I use that variable n in later lines of code.
But i dont need all dhcp lease, only with PC hostname, we solve that, but what is difference with that code and this
:global n [ip dhcp-server lease get [find host-name=PC] address];/file print file=$n
Why this line of code gave me errors...
 
sindy
Forum Guru
Forum Guru
Posts: 10206
Joined: Mon Dec 04, 2017 9:19 pm

Re: multiple lines into one

Mon Aug 20, 2018 11:42 pm

:global n [ip dhcp-server lease get [find host-name=PC] address];/file print file=$n
This line of code says:
- set the value of a global-scoped variable named n to the ip address leased to device with hostname PC
- print the list of existing files into a file whose name is retrieved from the global variable n
So you end up with a file named ip.add.re.ss.txt. which contains a list of all files currently available on the machine. On my machine it gives no errors if entered directly, so if it causes trouble via ssh, you either haven't used single quotes as Metod has recommended or there is some other error.

/file print is equivalent to ls / in linux; /file print file=something is equivalent to ls / > something
 
tomislav91
Member
Member
Topic Author
Posts: 303
Joined: Fri May 26, 2017 12:47 pm

Re: multiple lines into one

Mon Aug 20, 2018 11:55 pm

:global n [ip dhcp-server lease get [find host-name=PC] address];/file print file=$n
This line of code says:
- set the value of a global-scoped variable named n to the ip address leased to device with hostname PC
- print the list of existing files into a file whose name is retrieved from the global variable n
So you end up with a file named ip.add.re.ss.txt. which contains a list of all files currently available on the machine. On my machine it gives no errors if entered directly, so if it causes trouble via ssh, you either haven't used single quotes as Metod has recommended or there is some other error.

/file print is equivalent to ls / in linux; /file print file=something is equivalent to ls / > something
I understand, but what is difference with this line:
ip dhcp-server lease print file=$n
This return result of command to variable n, am I right?
And this works fine, do what I want (txt file with dhcp lease results).

So this is a little much information for me, and I want only ip of hostname PC, i got Ip with this:
ip dhcp-server lease get [find host-name=pc] address
So now is a problem within scripting, 'cause part of my old script (i mentioned earlier now) is
ip dhcp-server lease print file=$n
so can I somehow update it with that that gives me only IP, not whole dhcp lease...

Result of bash script was a txt file with IP address of PC

example:
newyork.txt
192.168.1.51
Last edited by tomislav91 on Tue Aug 21, 2018 7:42 am, edited 1 time in total.
 
sindy
Forum Guru
Forum Guru
Posts: 10206
Joined: Mon Dec 04, 2017 9:19 pm

Re: multiple lines into one

Tue Aug 21, 2018 12:25 am

If you really do want the file name to be sourced from variable n as you suggest, you have to do what I wrote earlier.

There is no file modifier to put, nor there is a way to make print print a single value.

So you have to generate a file with any bogus contents:
/routing print file=$n
and then replace the bogus contents with the one you want:
/file set ($n.".txt") contents=[/ip dhcp-server lease get [find host-name=kladionica] address]

Radiš previše stvari istovremeno i teško je da sa orijentiram što je u stvari problematično.
 
tomislav91
Member
Member
Topic Author
Posts: 303
Joined: Fri May 26, 2017 12:47 pm

Re: multiple lines into one

Tue Aug 21, 2018 8:35 am

If you really do want the file name to be sourced from variable n as you suggest, you have to do what I wrote earlier.

There is no file modifier to put, nor there is a way to make print print a single value.

So you have to generate a file with any bogus contents:
/routing print file=$n
and then replace the bogus contents with the one you want:
/file set ($n.".txt") contents=[/ip dhcp-server lease get [find host-name=kladionica] address]

Radiš previše stvari istovremeno i teško je da sa orijentiram što je u stvari problematično.
I will try it as soon as possible.
This must work for me in sshpass.
Idea is:
You have a host file with names and l2tp addresss to routers..
For example:
Newyork 10.10.10.10
Berlin 20.20.20.20

Then I run my linux bash script which run through all l2tp routers from host file, DO SSHPASS, get dhcp lease and make into my linux maschine file newyork.txr,berlin.txt contain result of command ip dhcp-server lease...
This is working just fine, just I need to do it with only ip woth pc hostname,i do not need whole dhcp.

Imas li neki email,face ili nesti da ti pustim skriptu,bukvalno ima 10ak linija koda a tipa 3 linijr rade posao.
 
User avatar
mkx
Forum Guru
Forum Guru
Posts: 11624
Joined: Thu Mar 03, 2016 10:23 pm

Re: multiple lines into one

Tue Aug 21, 2018 8:38 am

If you're going to fetch lease info from linux box via ssh, then you can easily do filtering with some simple commands on linux box itself.

One-liner that does the trick:
WANTED=my-host-name; LEASES=$( ssh user@routerboard.my.domain '/ip dhcp-server lease { :foreach i in=[find (!dynamic && status="bound")] do={ :local activeAddress [get $i active-address]; :local activeMacAddress [get $i active-mac-address]; :local hostname [get $i host-name]; :put ($outputContent . "\n" . $activeAddress . "," . $activeMacAddress . "," . $hostname) } }' ) ; echo ${LEASES} | grep ${WANTED} | cut -d, -f1
or, to make a script that takes hostname as argument:
#!/usr/bin/env bash
WANTED=$1
if [ -z "${WANTED}" ]; then
    echo 'Error! You have to specify host name as single argument.' >&2
    exit 1
fi
RB=user@routerboard.my.domain
LEASES=$( ssh ${RB} '/ip dhcp-server lease { :foreach i in=[find (!dynamic && status="bound")] do={ :local activeAddress [get $i active-address]; :local activeMacAddress [get $i active-mac-address]; :local hostname [get $i host-name]; :put ($outputContent . "\n" . $activeAddress . "," . $activeMacAddress . "," . $hostname) } }' )
echo ${LEASES} | grep ${WANTED} | cut -d, -f1
save it as a file and then run it, giving it host name, for which you want to get IP address from lease. Adjust whatever is assigned to variable RB, to correct value for your case (user might be admin, host name might be IP address if your RB doesn't have FQDN available from your DNS service.
If you want to fetch leased IP address for more than one host, you can replace the last line with a loop, looping through host names of interest. No need for multiple ssh lease fetches.
 
tomislav91
Member
Member
Topic Author
Posts: 303
Joined: Fri May 26, 2017 12:47 pm

Re: multiple lines into one

Tue Aug 21, 2018 10:08 am

If you're going to fetch lease info from linux box via ssh, then you can easily do filtering with some simple commands on linux box itself.

One-liner that does the trick:
WANTED=my-host-name; LEASES=$( ssh user@routerboard.my.domain '/ip dhcp-server lease { :foreach i in=[find (!dynamic && status="bound")] do={ :local activeAddress [get $i active-address]; :local activeMacAddress [get $i active-mac-address]; :local hostname [get $i host-name]; :put ($outputContent . "\n" . $activeAddress . "," . $activeMacAddress . "," . $hostname) } }' ) ; echo ${LEASES} | grep ${WANTED} | cut -d, -f1
or, to make a script that takes hostname as argument:
#!/usr/bin/env bash
WANTED=$1
if [ -z "${WANTED}" ]; then
    echo 'Error! You have to specify host name as single argument.' >&2
    exit 1
fi
RB=user@routerboard.my.domain
LEASES=$( ssh ${RB} '/ip dhcp-server lease { :foreach i in=[find (!dynamic && status="bound")] do={ :local activeAddress [get $i active-address]; :local activeMacAddress [get $i active-mac-address]; :local hostname [get $i host-name]; :put ($outputContent . "\n" . $activeAddress . "," . $activeMacAddress . "," . $hostname) } }' )
echo ${LEASES} | grep ${WANTED} | cut -d, -f1
save it as a file and then run it, giving it host name, for which you want to get IP address from lease. Adjust whatever is assigned to variable RB, to correct value for your case (user might be admin, host name might be IP address if your RB doesn't have FQDN available from your DNS service.
If you want to fetch leased IP address for more than one host, you can replace the last line with a loop, looping through host names of interest. No need for multiple ssh lease fetches.
Look this bash script:
#!/bin/bash
user=admin
read -sp 'Password ' pass
log=StrictHostKeyChecking=no
locdir=/root/testbash/mikrotik/dhcp_lease
rm -rf /root/.ssh/known_hosts
d=$(date '+%d-%b-%Y')
mkdir $locdir/Company_$d
cd $locdir/Company_$d
while read n h;do
sshpass -p $pass ssh -o $log -n $user@$h -p 4111 ip dhcp-server lease print file=$n
sshpass -p $pass sftp -oStrictHostKeyChecking=no -oPort=4111 $user@$h:$n.txt
sshpass -p $pass ssh -o $log -n $user@$h -p 4111 file remove $n.txt
done < $locdir/hosts.txt
THis is script which give me output i desire, whole dhcp lease.
I now want to have only IP address of my hostname PC.
 
tomislav91
Member
Member
Topic Author
Posts: 303
Joined: Fri May 26, 2017 12:47 pm

Re: multiple lines into one

Tue Aug 21, 2018 10:31 am

Because a dash was missing in what I wrote. Now I got home and tried using the Tab button:
[me@MyTik] > put [ip dhcp-server lease get [find host-name=my-HP] address]
192.168.88.254
if I have more than one with same name, it throws me
invalid internal item number
 
User avatar
mkx
Forum Guru
Forum Guru
Posts: 11624
Joined: Thu Mar 03, 2016 10:23 pm

Re: multiple lines into one

Tue Aug 21, 2018 10:39 am

I'm not familiar with sshpass but judging from the on-line documentation it will return stdout from remote process just like ssh does.

You have two possibilities:
  1. you can take whole output from your script (I don't know how exactly does it look like, are data fields comma-separated within single line or what) and filter only columns you need from that output. But form what I understand you over complicate the process of getting the lease data from routerboard ...
  2. you can adjust your script so that only IP address is output from the script itself. You can achieve that by filtering results from individual sshpass calls ...
My guess is that you can use sshpass in your script in the following manner:
LEASE_IP=$( sshpass -p $pass ssh -o $log -n $user@$h -p 4111 ''/ip dhcp-server lease { :foreach i in=[find (!dynamic && status="bound")] do={ :local activeAddress [get $i active-address]; :local activeMacAddress [get $i active-mac-address]; :local hostname [get $i host-name]; :put ($outputContent . "\n" . $activeAddress . "," . $activeMacAddress . "," . $hostname) } }' | grep $h | cut -d, -f1 )
IP address of host name $h should be now in variable LEASE_IP and you can do with it whatever you want. Stick it into the while loop instead of three calls to sshpass you currently have.
If you have many hosts in DHCP lease list with similar names, the simple "grep" above might return false positives ... in that case you may want to tinker with it so that it will only return single result (the wanted one).

I would really avoid fancy filtering to be done on ROS as Linux host offers many powerful tools to do it and you're using linux anyway. The cost of filtering on linux is more data transferred out of ROS, but I guess this should not be deciding factor unless you have many thousand leases on every RB device you're polling.
 
tomislav91
Member
Member
Topic Author
Posts: 303
Joined: Fri May 26, 2017 12:47 pm

Re: multiple lines into one

Tue Aug 21, 2018 11:19 am

I'm not familiar with sshpass but judging from the on-line documentation it will return stdout from remote process just like ssh does.

You have two possibilities:
  1. you can take whole output from your script (I don't know how exactly does it look like, are data fields comma-separated within single line or what) and filter only columns you need from that output. But form what I understand you over complicate the process of getting the lease data from routerboard ...
  2. you can adjust your script so that only IP address is output from the script itself. You can achieve that by filtering results from individual sshpass calls ...
My guess is that you can use sshpass in your script in the following manner:
LEASE_IP=$( sshpass -p $pass ssh -o $log -n $user@$h -p 4111 ''/ip dhcp-server lease { :foreach i in=[find (!dynamic && status="bound")] do={ :local activeAddress [get $i active-address]; :local activeMacAddress [get $i active-mac-address]; :local hostname [get $i host-name]; :put ($outputContent . "\n" . $activeAddress . "," . $activeMacAddress . "," . $hostname) } }' | grep $h | cut -d, -f1 )
IP address of host name $h should be now in variable LEASE_IP and you can do with it whatever you want. Stick it into the while loop instead of three calls to sshpass you currently have.
If you have many hosts in DHCP lease list with similar names, the simple "grep" above might return false positives ... in that case you may want to tinker with it so that it will only return single result (the wanted one).

I would really avoid fancy filtering to be done on ROS as Linux host offers many powerful tools to do it and you're using linux anyway. The cost of filtering on linux is more data transferred out of ROS, but I guess this should not be deciding factor unless you have many thousand leases on every RB device you're polling.
I found strange, this is my code now
#!/bin/bash
user=admin
read -sp 'Password ' pass
log=StrictHostKeyChecking=no
locdir=/etc/ansible/
rm -rf /root/.ssh/known_hosts
d=$(date '+%d-%b-%Y')
mkdir $locdir/Company_$d
cd $locdir/Company_$d
while read n h;do
LEASE_IP=$( sshpass -p $pass ssh -o $log -n $user@$h -p 4111 ''/ip dhcp-server lease { :foreach i in=[find (!dynamic && status="bound")] do={ :local activeAddress [get $i active-address]; :local activeMacAddress [get $i active-mac-addre$
#sshpass -p $pass ssh -o $log -n $user@$h -p 4111 ip dhcp-server lease print file=$n
#sshpass -p $pass sftp -oStrictHostKeyChecking=no -oPort=4111 $user@$h:$n.txt
#sshpass -p $pass ssh -o $log -n $user@$h -p 4111 file remove $n.txt
done < $locdir/hosts11.txt
I am having error
command substitution: line 12: syntax error near unexpected token `('
I find that before ip dhcp server part we have two ' but only one closed after :put ($outputContent . "\n" . $activeAddress . "," . $activeMacAddress . "," . $hostname) } }
I closed it, but now this error i posted above.
 
sindy
Forum Guru
Forum Guru
Posts: 10206
Joined: Mon Dec 04, 2017 9:19 pm

Re: multiple lines into one

Tue Aug 21, 2018 11:38 am

jbg... now I finally understand how you mix things :-)

First, your last snapshot shows that $n is a variable in bash, not in ROS script, which explains one part - you want to create (fetch, whatever) the file name already in linux and send it to the ROS script for use there.

Second, get returns a single scalar value, so if the result of the find is not an id of a single item (lease), the get fails with the error message you can see.

So you have to work with the list of element ids returned by find using foreach:

local listOfAddr;foreach lease in=[/ip dhcp-server lease find host-name=kladionica] do={set listOfAddr ($listOfAddr.[/ip dhcp-server lease get $lease address].";")};/routing rip print file=svakako-ime;/file set svakako-ime.txt contents=$listOfAddr

Now to do that from bash, you need to replace svakako-ime by $n but in a way that bash sends the contents of $n to the Mikrotik already expanded, so you must add the single quotes the following way:

'local listOfAddr;foreach lease in=[/ip dhcp-server lease find host-name=kladionica] do={set listOfAddr ($listOfAddr.[/ip dhcp-server lease get $lease address].";")};/routing rip print file='$n';/file set '$n'.txt contents=$listOfAddr'
 
User avatar
mkx
Forum Guru
Forum Guru
Posts: 11624
Joined: Thu Mar 03, 2016 10:23 pm

Re: multiple lines into one

Tue Aug 21, 2018 1:55 pm

Arghhh ... I don't know where he surplus quote came from ...
I found strange, this is my code now
LEASE_IP=$( sshpass -p $pass ssh -o $log -n $user@$h -p 4111 ''/ip dhcp-server lease { :foreach i in=[find (!dynamic && status="bound")] do={ :local activeAddress [get $i active-address]; :local activeMacAddress [get $i active-mac-address]; :local hostname [get $i host-name]; :put ($outputContent . "\n" . $activeAddress . "," . $activeMacAddress . "," . $hostname) } }' | grep $h | cut -d, -f1 )
The extra single quote is one of opening quotes: .... -p4111 '/ip .... only single quote should be there.
 
tomislav91
Member
Member
Topic Author
Posts: 303
Joined: Fri May 26, 2017 12:47 pm

Re: multiple lines into one

Tue Aug 21, 2018 3:17 pm

Thanks all for you replies!
appreciate!!!

I did it like this.
Get in the first way, all dhcp lease, and than with some command filter only IP addresses
grep -i -w kl locations.txt > locations1.txt;cat locations1.txt | awk -F " " '{print $2, $3}' > locations2.txt; sed 's/D//g' locations2.txt > locations3.txt;cat locations3.txt |grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' >locations333.txt

Who is online

Users browsing this forum: Bing [Bot], MauriceW and 92 guests