Community discussions

MikroTik App
 
dima1002
Member Candidate
Member Candidate
Topic Author
Posts: 160
Joined: Fri Jan 26, 2018 8:40 pm

How can I write here from line 1 to 50?

Tue Feb 22, 2022 10:30 am

Hello,

how can I write here e.g. from line 1 to 100?

e.g.
/system/logging/remove numbers= 1-100
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: How can I write here from line 1 to 50?

Tue Feb 22, 2022 11:17 am

What is your goal? Remove all logging config?
 
dima1002
Member Candidate
Member Candidate
Topic Author
Posts: 160
Joined: Fri Jan 26, 2018 8:40 pm

Re: How can I write here from line 1 to 50?

Tue Feb 22, 2022 11:38 am

Yes.
But I would also like to know in general how to write such scripts?
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: How can I write here from line 1 to 50?

Tue Feb 22, 2022 3:44 pm

You can do
:for i from=0 to=50 do={ :put $i }
But take care!!
What you see from /system logging print
Flags: X - disabled, I - invalid, * - default 
 #    TOPICS                                     ACTION                                     PREFIX    
 0 X* info                                       memory                                               
 1  * error                                      memory                                               
 2  * warning                                    memory                                               
 3  * critical                                   echo                                                 
 4    dhcp                                       logserver                                  MikroTik  
 5    !debug                                     logserver                                  MikroTik  
      !packet                                   
 6    hotspot                                    logserver                                  MikroTik  
Use find to find line numbers and thy are in hex
:put [/system logging find]
*1;*2;*3;*4;*5;*6;*7
As you see, number are not equal. This is not the same as number as you use in script. Script numbers are internally, so it will fail to do what you think it should do.

"find" is the way to find some in config.
So to "try" to delete all log lines
/system logging
:foreach i in=[find] do={remove $i}
This will also fail, since it can not remove default rules.

You must ignore default rules:
/system logging
:foreach i in=[find  default=no] do={remove $i}
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3250
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: How can I write here from line 1 to 50?

Tue Feb 22, 2022 6:59 pm

You can't delete log entries, and from a security/audit POV, it make sense.

While you view logs using the terminal using...
# all
/log print
# filter by topic (~ mean a regular expression, in most cases that means a "partial match")
/log print where topics~"debug"
# filter by message contents
/log print where message~"changed"
The logs aren't that scriptable, other than using
/log print file=
to export them to then parse from the log file, use /tool/email to forward them, etc.

See viewtopic.php?p=885626&hilit=log+variable#p885626
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: How can I write here from line 1 to 50?

Tue Feb 22, 2022 8:00 pm

From this in OPs post "/system/logging/remove", I do assume he is talking about deleting configuration of logging, not logging entries (that can not be deleted).
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3250
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: How can I write here from line 1 to 50?

Tue Feb 22, 2022 8:38 pm

From this in OPs post "/system/logging/remove", I do assume he is talking about deleting configuration of logging, not logging entries (that can not be deleted).
Totally. I'm just more thinking how many log rules could you have that require scripting... Either way
[$op [find~"log|logging"] $solution]
.

Who is online

Users browsing this forum: bertus and 23 guests