Remove connection from script

Hi I’m trying to remove a connection from a script but I can’t seem to get it to work.

On the Mikrotik box after visually getting the connection number with:

/ip firewall connection print
and removing with:
/ip firewall connection remove 5
This is no problem from a Mikrotik terminal/console.
However if I put this command in a script or try to execute via ssh I get the following error:
(run from a linux server)

ssh admin@1.1.1.1 ‘/ip firewall connection remove 5’

syntax error (line 1 column 32).
yet
#ssh admin@1.1.1.1 ‘/ip firewall connection print’
works.

What I want to do is look for a specfic connection based on some criteria eg. connection-type or whatever.
Then capture the connection number and remove it.
I am able to do all of the above programatically except remove the connection.
This it seems is only successfull when run from the terminal directly on the Mikrotik.
What am I missing?

you can’t use number given out by console print
You have to use find command. Search the forum. Even today one customer asked the same question.

first topic in this section
http://forum.mikrotik.com/t/help-on-script-to-extract-sms-inbox-text-message/28760/1

Fair enough but the
/ip firewall connection remove command
only seems to except an id number.
How would I remove a specific connection (As I would from the gui) ?
I’ve looked at this thread:
http://forum.mikrotik.com/t/remove-all-connections/4727/1
They seem to have the same problem.
find doesn’t produce any results.

Actually it does:

[admin@gw-loc] /ip firewall connection> :put [find tcp-state="established"]
*5;*6;*7;*8;*d;*f;*11;*14;*17;*18;*19;*1c

Thanks, I could have swore I tried that exact command with no results… ???
However could you be a little more specific?
I don’t know what to do with that output?
I want a way to list and then remove an item.
To be more specific… (for example)
I want to remove anything with dst-address=1.1.1.1:111
Thanks again in advance.

!!! I got it.!!!
Thanks to your help and alot of digging the command I’m using is
/ip firewall connection {:foreach i in [find dst-address=“1.1.1.1:111”] do={remove $i}}

did you try

/ip firewall connection { remove [find dst-address="1.1.1.1:111"] }

? =)

it should be quicker…

Even better,
Thank you