Community discussions

MikroTik App
 
mudasir
Member Candidate
Member Candidate
Topic Author
Posts: 278
Joined: Tue Apr 29, 2008 3:38 am
Location: Karachi, Pakistan
Contact:

Error in Script with SSH

Sun Sep 05, 2010 4:29 am

Hi,

I am working on a script to show all active interfaces in PPTP. The script is working fine when run in mikrotik console. I want to execute this script through SSH, it gives error when executed through SSH.
:global iname;:foreach i in=[/interface find type=pptp-in] do={:set iname [interface get $i name] ;:put $iname}
It shows the last interface in the list and give the following error.

"expected end of command (line 1 column 86)"

When i run this same script in MT console, it works fine.

How can i resolve this error.
 
changeip
Forum Guru
Forum Guru
Posts: 3830
Joined: Fri May 28, 2004 5:22 pm

Re: Error in Script with SSH

Sun Sep 05, 2010 7:19 pm

you probably need escape the : with backslashes. ALso, you should put any parameters in quotes, especially those with dashes in them, ie type="pptp-in"

try this:

":foreach i in=[/interface find type=""pptp-in""] do={\:put [/interface get $i name];}"

Didnt test, but should be close to what you need. . .
 
psamsig
Member Candidate
Member Candidate
Posts: 161
Joined: Sun Dec 06, 2009 1:36 pm
Location: Denmark

Re: Error in Script with SSH

Sun Sep 05, 2010 11:01 pm

Really no need to use :global, and i think your problem is that the 'interface get' requires that it is run in the root context (where as '/interface get' is not)
/interface {:local iname; :foreach i in=[find type=pptp-in] do={:set iname [get $i name]; :put $iname}}
or as I would format it:
/interface {
    :local iname
    :foreach i in=[find type=pptp-in] do={
        :set iname [get $i name]
        :put $iname
    }
}
 
dssmiktik
Forum Veteran
Forum Veteran
Posts: 732
Joined: Fri Aug 17, 2007 8:42 am

Re: Error in Script with SSH

Mon Sep 06, 2010 7:53 pm

Just to add to psamsig's approach (no variables required):

Tested and working code:
ssh <user>@<router> '/interface {:foreach i in=[find type="pptp-in"] do={:put [get $i name]}}'

Who is online

Users browsing this forum: No registered users and 26 guests