Email Daily Report for Entire Log

Hello,

I have found a script to send me mail if there’s any failure login. May I get your expertise comment how to get a entire log (not just login failure) and send email to me daily?

Here below is the script that to send me log for failure login only:
:local scheduleName “Email_log_file_2”
:local emailAddress “mymail@mymail.com
:local startBuf [:toarray [/log find message~“logged in” || message~“login failure”]]
:local removeThese (“”)

:local lastTime [/system scheduler get [find name=“$scheduleName”] comment]

:local currentBuf “”; :set currentBuf [:toarray $currentBuf]

:foreach i in=$startBuf do={
:local toggle 1
:foreach j in=[:toarray $removeThese] do={
:if ([:typeof [:find [/log get $i message] “$j”]] = “num”) do={
:set toggle 0
}
}
:if ($toggle = 1) do={
:set currentBuf ($currentBuf , $i)
}
}

:local currentLineCount [ :len $currentBuf ]

if ($currentLineCount > 0) do={
:local currentTime “$[ /log get [ :pick $currentBuf ($currentLineCount -1) ] time ]”

:if ([:len $currentTime] = 15 ) do={
:set currentTime [ :pick $currentTime 7 15 ]
}

:local output “$currentTime $[/log get [ :pick $currentBuf ($currentLineCount-1) ] message ]”

:if (([:len $lastTime] < 1) || (([:len $lastTime] > 0) && ($lastTime != $currentTime))) do={
/system scheduler set [find name=“$scheduleName”] comment=$currentTime
/tool e-mail send to=“$emailAddress” subject=“MikroTik alert $currentTime” body=“$output”
}
}


Thank you.

Event, I have tried to modify the script to
:local startBuf [:toarray [/log]]

There’s no mail being sent for the entire log.

Please kindly help for how to generate the whole log.

Thank you.

I am logging to file placed at USB flash disk:

/system logging action
set 1 disk-file-count=20 disk-file-name=/usb1/log disk-lines-per-file=2000
/system logging
set 0 action=disk
set 1 action=disk
set 2 action=disk
set 3 action=disk

Then regularly sending the last file from all logging files by script via e-mail:

/system script
add name=LogToEmail policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source=":log info \
    \"LogToEmail: Sending by e-mail\"\r\
    \n/tool e-mail send to=\"my.email@somewhere.tld\" subject=([/system identity get name] . \\\r\
    \n\" SystemLog\") from=mikrotik@whatever.tld file=usb1/log.0.txt\r\
    \n:log info \"LogToEmail: Successfully finished\""

This script is scheduled with daily interval.

You can do the same… Of course you have to have set your e-mail settings (installed “advanced-tools” package).

Thanks for your information.

How to modify the script without save the log file into the USB? I just want to retrieve the log file and send by email directly.

Thank you.

You can save it to local disk. If log is not saved then each reboot deletes it.