Community discussions

 
Trojahn
just joined
Topic Author
Posts: 20
Joined: Wed May 24, 2006 5:20 pm
Location: Rio de Janeiro, Brazil

Filtering a command output

Wed Jun 07, 2006 4:05 pm

Hello,

I never tried MT scripting so I'm having a little trouble to make this work...

Consider the command "ppp active print detail without-paging"... Let's say I need to filter its output to only show me the lines where the usernames start with the letter "a"...

How can I do that?

Thanks in advance.
 
User avatar
Eugene
Forum Veteran
Forum Veteran
Posts: 993
Joined: Mon May 31, 2004 5:06 pm
Location: Cranfield, UK

Thu Jun 08, 2006 5:04 pm

The following command if pasted into the terminal will print all ppp active users having names starting from "ex":

:global list ""; :foreach i in [/ppp active find] do={:if ([:find [/ppp active get $i name] "ex"]=0) do={:set list ($list . "," . $i);}}; /ppp active print detail without-paging from $list;


Eugene
Tout individu a droit à la vie, à la liberté et à la sûreté de sa personne.
 
eflanery
Member
Member
Posts: 382
Joined: Fri May 28, 2004 10:11 pm
Location: Moscow, ID
Contact:

Thu Jun 08, 2006 6:44 pm

I would point this out as another example of why something like 'grep' would be a wonderful addition.

/ppp active print detail without-paging | grep ex

would be much quicker, and so much more obvious to many people.

--Eric
 
User avatar
Eugene
Forum Veteran
Forum Veteran
Posts: 993
Joined: Mon May 31, 2004 5:06 pm
Location: Cranfield, UK

Thu Jun 08, 2006 8:07 pm

How about this: "It's inherently fun to program" :)
Tout individu a droit à la vie, à la liberté et à la sûreté de sa personne.
 
eflanery
Member
Member
Posts: 382
Joined: Fri May 28, 2004 10:11 pm
Location: Moscow, ID
Contact:

Thu Jun 08, 2006 8:51 pm

True, and I don't have much of a problem composing cryptic statements, but the same cannot be said for everyone.

There are many times when our tech support group has expressed frustration at the difficulty of searching in RouterOS. I usually end up telling them to use Winbox, sort on the column of their choice, and scroll through until they find what they are looking for. It's inefficient, but it's easier than trying to debug long commands (especially when ROS doesn't really have any debugging tools), and much easier than trying to explain the complexities of ROS syntax to a first-year collage student answering phones.

On the other hand, with the vendor C gear, I can simply tell them to do a 'sh ip arp | incl 0c13', for example. Simple, and concrete. There just isn't an equivalent in ROS that can be handled by a $9/hr tech. In general, MT gear is much more user friendly than vendor C's, but in this particular area, MT is lacking.

Even I would often rather type 15 characters and be done with it, rather than stretching the command out to 100+. It would also be quite nice to have regular expressions available, for those more complex searches.

Once the API is released, this will likely become moot, since we will be more easily able to create our own interfaces (yes, it can be done now with SSH and Expect, but that gets has it's own problems). But at this time, the lack of an easy search function is one of the biggest frustrations we have with MT.

--Eric
 
User avatar
Eugene
Forum Veteran
Forum Veteran
Posts: 993
Joined: Mon May 31, 2004 5:06 pm
Location: Cranfield, UK

Thu Jun 08, 2006 9:04 pm

well, if you would use ssh key authentication, than you could get easy search in ROS:

ssh 10.5.8.1 /ppp active print | grep -E "Your regular expression goes here"

Eugene
Tout individu a droit à la vie, à la liberté et à la sûreté de sa personne.
 
Trojahn
just joined
Topic Author
Posts: 20
Joined: Wed May 24, 2006 5:20 pm
Location: Rio de Janeiro, Brazil

Thu Jun 08, 2006 9:37 pm

Yes... I'm aware of grep and that's what I'm using for now... But what eflanery said is true, a command inside MT would be alot more useful... And I would go a little more far than that... Not a grep, but something that would make the "ppp active print" list only what u ask so it wouldn't have all the stress of going on 1000 users to print just 2 of them...

Sorry about any grammar mistakes... English isn't my first language...
 
eflanery
Member
Member
Posts: 382
Joined: Fri May 28, 2004 10:11 pm
Location: Moscow, ID
Contact:

Thu Jun 08, 2006 11:57 pm

well, if you would use ssh key authentication, than you could get easy search in ROS:

ssh 10.5.8.1 /ppp active print | grep -E "Your regular expression goes here"

Eugene
And, if you want to do it with a live session, with telnet, or ssh without key-auth, you can do something (with a pair of terminals) like:

Terminal 1: mkfifo fifo; cat fifo | grep -E "regex of choice"

Terminal 2: script -f fifo

Then in terminal 2, connect to the MT, do your thing, and watch for the filtered results in terminal 1.

I'm not saying there aren't ways to get it done, there are many. I'm saying there is nothing quick and easy built-in, and that leads to frustration.

--Eric
 
User avatar
thavinci
Member
Member
Posts: 334
Joined: Sat Aug 04, 2007 4:40 pm
Location: Johannessburg
Contact:

Re: Filtering a command output

Mon Apr 28, 2008 4:25 am

Flip, would love to have grep.
I am an experianced linux/unix admin and infrastructure expert, not not a bloody programmer!

I normally work this stuff out after few hours, but is such a waste of time!

Hope fully someone can help!

Im trying to overcome yet another bug in MT.

it seems that my web-proxy often stops working.

it would be nice if i could do a "ip proxy monitor once" and filter for status to restart it eventually!

Tried modifying above code to ...
:global list ""; :foreach i in [/ip proxy monitor once find] do={:if ([:find [/ppp active get $i name] "status"]=0) do={:set list ($list . "," . $i);}}; /ip proxy monitor once from $list; 
Didn't work
No idea how im supposed to do this.
http://www.thavinci.za.net

echo "Demo license expired!"
echo "Please reinstall the router."
echo
kill -WINCH 1
exit
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 5934
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Filtering a command output

Mon Apr 28, 2008 2:09 pm

[/ip proxy monitor once find] will not work because there is nothing to find.
 
User avatar
thavinci
Member
Member
Posts: 334
Joined: Sat Aug 04, 2007 4:40 pm
Location: Johannessburg
Contact:

Re: Filtering a command output

Fri May 02, 2008 12:52 pm

How would i specify what to find/filter?
http://www.thavinci.za.net

echo "Demo license expired!"
echo "Please reinstall the router."
echo
kill -WINCH 1
exit
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 5934
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Filtering a command output

Fri May 02, 2008 4:23 pm

Just what you want to achieve by using this command?

[/ip proxy monitor once find]

This is completely wrong and I can't figure out what exactly you want to find.
 
User avatar
thavinci
Member
Member
Posts: 334
Joined: Sat Aug 04, 2007 4:40 pm
Location: Johannessburg
Contact:

Re: Filtering a command output

Fri May 02, 2008 4:44 pm

I would like to find the status of the web-proxy.

ie, to see if it's state is "running" or "stopped"

Thank You.
http://www.thavinci.za.net

echo "Demo license expired!"
echo "Please reinstall the router."
echo
kill -WINCH 1
exit
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 5934
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Filtering a command output

Fri May 02, 2008 4:49 pm


  /ip porxy monitor once do={ 
     :if ( $state = "running" ) do={
          :log info "Proxy is running";
     }
  }

 
User avatar
thavinci
Member
Member
Posts: 334
Joined: Sat Aug 04, 2007 4:40 pm
Location: Johannessburg
Contact:

Re: Filtering a command output

Fri May 02, 2008 5:31 pm

That is exactly what i wan't to do!!!!

However i tried to use that code and nothing happens. :/

I open log to watch for output. I check that proxy is indeed running.

I create it in scheduler with 1 second interval, no output.
Tried in scripts aswell, obviously running it manually there.

thank You so much for input so far!
I have been desperate to solve this as web-proxy keeps crashing and i need something to start it up again.
http://www.thavinci.za.net

echo "Demo license expired!"
echo "Please reinstall the router."
echo
kill -WINCH 1
exit
 
yeah
just joined
Posts: 7
Joined: Mon Sep 20, 2010 4:30 pm

Re: Filtering a command output

Fri Jan 24, 2014 6:29 pm

I want to print in consle dhch-server leases, that belongs to network 192.168.106.0/24
In console i run
ip dhcp-server lease print where address in 192.168.106.0/24
and it don`t give me any output.
What am i doing wrong?
 
yeah
just joined
Posts: 7
Joined: Mon Sep 20, 2010 4:30 pm

Re: Filtering a command output

Wed Feb 19, 2014 4:41 pm

Can anybody help me?
 
mike99
just joined
Posts: 7
Joined: Tue Nov 10, 2015 11:52 pm
Location: Montreal

Re:

Tue Nov 13, 2018 7:01 pm

/ppp active print detail without-paging | grep ex
Maybe the following
/ppp active print detail without-paging where user~"ex"

P.S.:
Old thread but one of the first one to be shown on google for grap like answer.

Who is online

Users browsing this forum: MSN [Bot] and 9 guests