Page 1 of 1

How to filter logging time 24 hours ago and topics=ppp and message=connected in log.0.txt

Posted: Wed Jan 22, 2025 6:05 am
by bara
halo
can help me.
i stuck to find script filter logging time 24 hours ago and topics=ppp and message=connected and save become new file txt
this is script i created and running but just can filter topics ppp and message connected
:local fileconten [/file/get ppp_log.0.txt contents]

:local scriptfilter [/log print file=ppp_connected_logs.txt where topics~"ppp" and  message~"connected"]
{
 :foreach Log in=$fileconten do={[$scriptfilter]
}
}
Thank You

Re: How to filter logging time 24 hours ago and topics=ppp and message=connected in log.0.txt

Posted: Wed Jan 22, 2025 5:33 pm
by ConnyMercier
Do you really need the "24 Hours" ??

I am asking, because that is relatively complex to execute....

Alternatively, it could be quite easy to write a script that exports the Log entries of the DAY.
In other words, a script that exports the Logs of the "Today 22.01.2025" instead of the "24 Hours"

Re: How to filter logging time 24 hours ago and topics=ppp and message=connected in log.0.txt

Posted: Thu Feb 20, 2025 5:18 am
by bara
Do you really need the "24 Hours" ??

I am asking, because that is relatively complex to execute....

Alternatively, it could be quite easy to write a script that exports the Log entries of the DAY.
In other words, a script that exports the Logs of the "Today 22.01.2025" instead of the "24 Hours"
I have tried export filter log 24 hours and not succes. like as you said is relatively complex to execute.
i have to try export the logs of the day

Re: How to filter logging time 24 hours ago and topics=ppp and message=connected in log.0.txt  [SOLVED]

Posted: Sun Mar 02, 2025 4:51 pm
by colinardo
HI @bara.

I have posted a quick and easy solution using current RouterOS versions (>=7.17) for this task here
Mikrotik Scripting - Quickly filter Router-Log by datetime

Examples for your specific needs:

Your entries since "24 hours ago":
/log print where (([:timestamp]+([/system clock get gmt-offset]."s"))-[:totime (time)]) <= 24h && message ~ "connected" && topics ~ "ppp"
or all logs starting the current day at midnight
/log print where [:totime (time)] >= [:totime [/system clock get date]] && message ~ "connected" && topics ~ "ppp"
or between two specified dates
/log print where [:totime (time)] >= [:totime "2025-02-27 00:00:00"] && [:totime (time)] < [:totime "2025-02-28 00:00:00"]  && message ~ "connected" && topics ~ "ppp"
Just choose the solution which fits your needs.

Regards @colinardo

Re: How to filter logging time 24 hours ago and topics=ppp and message=connected in log.0.txt

Posted: Thu Mar 06, 2025 8:31 am
by bara
HI @bara.

I have posted a quick and easy solution using current RouterOS versions (>=7.17) for this task here
Mikrotik Scripting - Quickly filter Router-Log by datetime

Examples for your specific needs:

Your entries since "24 hours ago":
/log print where (([:timestamp]+([/system clock get gmt-offset]."s"))-[:totime (time)]) <= 24h && message ~ "connected" && topics ~ "ppp"
or all logs starting the current day at midnight
/log print where [:totime (time)] >= [:totime [/system clock get date]] && message ~ "connected" && topics ~ "ppp"
or between two specified dates
/log print where [:totime (time)] >= [:totime "2025-02-27 00:00:00"] && [:totime (time)] < [:totime "2025-02-28 00:00:00"]  && message ~ "connected" && topics ~ "ppp"
Just choose the solution which fits your needs.

Regards @colinardo
Hi, thank you its working for me now i must learn your script its new for me. before i open this forum i try do this
:foreach Log in=filter do={
global formattedDate do={
:local date [/system clock get date]
:local month [:pick $date 5 7]
:local day [:pick $date 8 10]
:local year [:pick $date 0 4]
:return [($year . "-" . $month . "-" . ($day - 1))]
:set formattedDate [$formattedDate]
:put [$formattedDate]
}
:local Yesterday [$formattedDate]
/log print file=ppp_test_logs.txt where time~"Yesterday" && topics~"ppp" && message~"connected"
}

But not working