Page 1 of 1

script to save logs and send via email

Posted: Sat Mar 01, 2008 10:12 am
by xakou
Hi all,

i m looking for a script to save the logs 1 time per day (to my cf card) and then send it to my email.
Can anybody help me ?

Re: script to save logs and send via email

Posted: Sun Mar 02, 2008 7:16 am
by Letni
/system script add name="LogDump" policy=ftp,reboot,read,write,policy,test,winbox,password,sniff source="
:local body
:foreach int in=[/log find ] do={
  :set body ("$body\r\n" . [/log get $int])
}
/tool e-mail send to="YOU@DOMAIN.COM" subject=([/system identity get name] . " Log " . [/system clock get date]) body=$body
/system logging action set memory memory-lines=1
/system logging action set memory memory-lines=100"
/system script add disabled=no interval=1d name="Run Log Dump" on-event=LogDump start-date=jan/01/1970 start-time=00:00:00 
-Louis

Re: script to save logs and send via email

Posted: Sun Mar 02, 2008 1:40 pm
by xakou
/system script add name="LogDump" policy=ftp,reboot,read,write,policy,test,winbox,password,sniff source="
:local body
:foreach int in=[/log find ] do={
  :set body ("$body\r\n" . [/log get $int])
}
/tool e-mail send to="YOU@DOMAIN.COM" subject=([/system identity get name] . " Log " . [/system clock get date]) body=$body
/system logging action set memory memory-lines=1
/system logging action set memory memory-lines=100"
/system script add disabled=no interval=1d name="Run Log Dump" on-event=LogDump start-date=jan/01/1970 start-time=00:00:00 
-Louis
thank you for you reply....

I found at the forum, but again thank you very much!!!!

Btw, do u suggest any program to analysing this log files ?

Re: script to save logs and send via email

Posted: Sun Mar 02, 2008 4:05 pm
by jordantrx
/system script add name="LogDump" policy=ftp,reboot,read,write,policy,test,winbox,password,sniff source="
:local body
:foreach int in=[/log find ] do={
  :set body ("$body\r\n" . [/log get $int])
}
/tool e-mail send to="YOU@DOMAIN.COM" subject=([/system identity get name] . " Log " . [/system clock get date]) body=$body
/system logging action set memory memory-lines=1
/system logging action set memory memory-lines=100"
/system script add disabled=no interval=1d name="Run Log Dump" on-event=LogDump start-date=jan/01/1970 start-time=00:00:00 
-Louis
thank you for you reply....

I found at the forum, but again thank you very much!!!!

Btw, do u suggest any program to analysing this log files ?
wordpad :roll:

Re: script to save logs and send via email

Posted: Thu May 15, 2008 8:41 pm
by itsh.net
I wanted this script under V3.9 to work,
but unfortunately is not ..

Can someone help?


source="
:local body
:foreach int in=[/log find ] do={
  :set body ("$body\r\n" . [/log get $int])
}
/tool e-mail send to="YOU@DOMAIN.COM" subject=([/system identity get name] . " Log " . [/system clock get date]) body=$body
/system logging action set memory memory-lines=1
/system logging action set memory memory-lines=100"


Re: script to save logs and send via email

Posted: Fri May 16, 2008 6:01 am
by Letni
Modify this line
  :set body ("$body\r\n" . [/log get $int])
to
  :set body ("$body\r\n" . [/log get $int message])
I have a 153 at my house with v3.9. When I ran my original script my CPU went to 100%, then the routerboard would reboot after a couple of seconds. Modifying it with the message option seems to correct that issue.

-Louis

Re: script to save logs and send via email

Posted: Fri May 16, 2008 11:01 am
by itsh.net
Thanks for the Help @ Louis

I have the script a little added / modified.
It will now also the time in the body.
#read log
:local logcontent
:foreach int in=[/log find ] do={
:set logcontent ("$logcontent\r\n" .[/log get $int time]. " - " .[/log get $int message])
}
#send email
/tool e-mail send to="log@xxxx.xxx" subject=([/system identity get name] . " Log " . [/system clock get date]) body=$logcontent
#delete old log
/system logging action set memory memory-lines=1
/system logging action set memory memory-lines=65000


Re: script to save logs and send via email

Posted: Mon May 19, 2008 12:50 pm
by er
hej itsh.net
When I copy your script in terminal, I receive this ???
Ros = 2.9.49
[erik@Trekanten] > #read log
[erik@Trekanten] > :local logcontent
[erik@Trekanten] > :foreach int in=[/log find ] do={
{... :set logcontent ("$logcontent\r\n" .[/log get $int time]. " - " .[/log get $int message])
{... }
no such command or directory (find)
invalid expression
Erik

Re: script to save logs and send via email

Posted: Mon May 19, 2008 1:36 pm
by itsh.net
hey Erik

your must add to the Script (i had post the blank script)
and then run the Script
/system script add name="LogDump" policy=ftp,reboot,read,write,policy,test,winbox,password,sniff 

#read log
:local logcontent
:foreach int in=[/log find ] do={
:set logcontent ("$logcontent\r\n" .[/log get $int time]. " - " .[/log get $int message])
}
#send email
/tool e-mail send to="log@xxxx.xxx" subject=([/system identity get name] . " Log " . [/system clock get date]) body=$logcontent
#delete old log
/system logging action set memory memory-lines=1
/system logging action set memory memory-lines=65000

i used the V3.9 and the script run fine..

Re: script to save logs and send via email

Posted: Fri Mar 30, 2012 5:21 pm
by FlorinHiT
Heloo ,
I tried this script ,work very well in v5.14,but sometimes send e-mail log without date .
I planned a simulation and this is what sends :

jan/02/1970 02:00:12 - router rebooted
jan/02/1970 02:00:15 - ether1 link up (speed 100M, full duplex)
jan/02/1970 02:00:29 - ether1 link down
jan/02/1970 02:00:30 - ether1 link up (speed 100M, full duplex)
jan/02/1970 02:00:31 - ether1 link down
jan/02/1970 02:00:35 - ether1 link up (speed 100M, full duplex)
17:11:11 - ether1 link down
17:11:13 - ether1 link up (speed 100M, full duplex)
17:11:37 - ether1 link down
17:11:39 - ether1 link up (speed 100M, full duplex)
17:11:41 - ether1 link down
17:11:43 - ether1 link up (speed 100M, full duplex)

Re: script to save logs and send via email

Posted: Wed Oct 23, 2013 9:03 pm
by Ehman
awesome script, I use it on almost all my routers, but after a upgrade on my grooves, the script go's mental and kinda crash my router, leaving me a nice supout.rif file and no email! :?

Model: Groove A-52HPn
ROS: v6.3
firmware: 3.07

Re: script to save logs and send via email

Posted: Thu Oct 24, 2013 1:09 pm
by janisk
please upgrade to newer RouterOS version as scripting has had a lot of changes since 6.3

Re: script to save logs and send via email

Posted: Thu Oct 24, 2013 1:15 pm
by Ehman
I don't trust the new versions of ros [past experience] ...always tends to be full of bugs

Re: script to save logs and send via email

Posted: Thu Oct 24, 2013 1:15 pm
by normis
I don't trust the new versions of ros [past experience] ...always tends to be full of bugs
So known "non working" is better than "unknown"?

Re: script to save logs and send via email

Posted: Thu Oct 24, 2013 1:22 pm
by boen_robot
So known "non working" is better than "unknown"?
I think the logic goes more like "known to be little broken" is better than "maybe more broken".

Re: script to save logs and send via email

Posted: Thu Oct 24, 2013 1:58 pm
by Ehman
not to keen to kill 20 live AP's 400km away from me, will rather wait it out till someone else makes the mistake and in mean time, I'll order the same unit for demo and testing purpose with the new ros version

Re: script to save logs and send via email

Posted: Thu Oct 24, 2013 3:12 pm
by janisk
running this script successfully on by test router using 6.5

anyway, you could update to 6.5 and attempt if this problem still exist (on one router) if you still encounter the problem, just create support output file and send it to us (if there is autsupout.rif file then send that file also).

Re: script to save logs and send via email

Posted: Wed Jul 30, 2014 8:44 pm
by Ximi87
Hello friends.

I want to send my log in my email but i can not do that..
i try the script but it shows an error.

My router is SXT v.5.26

The code:

/system script add name="LogDump" policy=ftp,reboot,read,write,policy,test,winbox,password,sniff

#read log
:local logcontent
:foreach int in=[/log find ] do={
:set logcontent ("$logcontent\r\n" .[/log get $int time]. " - " .[/log get $int message])
}
#send email
/tool e-mail send to="gezimleka@gmail.com" subject=([/system identity get name] . " Log " . [/system clock get date]) body=$logcontent
#delete old log
/system logging action set memory memory-lines=1
/system logging action set memory memory-lines=65000

Please help me.

Re: script to save logs and send via email

Posted: Tue Aug 05, 2014 9:39 pm
by jarda
Why so complicated? Just log into file and sent the file regularly as email attachment.

Re: script to save logs and send via email

Posted: Fri Aug 15, 2014 7:29 pm
by Ximi87
can you tell me how to do that...

with script or with winbox.

Re: script to save logs and send via email

Posted: Sat Aug 16, 2014 7:42 am
by jarda
logging:

ros code

/system logging action
set 1 disk-file-count=20 disk-file-name=/usb1/log disk-lines-per-file=2000
regular script for sending:

ros code

/tool e-mail send to="my.email" subject=([/system identity get name] . \
" SystemLog") from=my.device.email file=usb1/log.0.txt
Have you read your error message posted here?? it says that script with such name already exists...

Re: script to save logs and send via email

Posted: Fri Jan 09, 2015 10:28 pm
by pgh321

ros code

/system logging action
set 1 disk-file-count=20 disk-file-name=/usb1/log disk-lines-per-file=2000
regular script for sending:

ros code

/tool e-mail send to="my.email" subject=([/system identity get name] . \
" SystemLog") from=my.device.email file=usb1/log.0.txt
I've just found this post, seems nice, but how do you do deal with duplicate or missing stuff?

for example, let's suppose I run your script daily, and there were few entries in the log, I'll see the same log twice. Instead if there were too many entries, maybe I'll just see log.0 but in the meanwhile there was another log.1 I will not see.
But, honestly, I've seen that implementing something like a log rotation and check to send only new logs becomes rapidly too much complicated and errors prone... Maybe I could just send file every two hour, and suppose I'll never log more than 1000 lines/hour :-)

Again, is there a way to send email IMMEDIATELY for certain events, for example admin logins? There's a log target "email", but there are no examples on it...

Re: script to save logs and send via email

Posted: Sun Jan 11, 2015 4:50 am
by jarda
You never can presume how the log will look like. If the logging is really essential you should run logserver and log from devices directly to it.
I remember that there were some script published here that was able to parse the log records and do actions according the log content. Search a bit.

Re: script to save logs and send via email

Posted: Sun Jan 11, 2015 1:19 pm
by pgh321
Yes, but if you are using your script above, how do you deal with it? How often do you send your file? thank you

Re: script to save logs and send via email

Posted: Sun Jan 11, 2015 2:15 pm
by jarda
I send emails with log file daily. Also exports and backups each two days. Parallely I use logserver in dude online. I am not so much interested in the content of logs just checking if it works correctly because sometimes the logging to disk stops without any other notice. So I mainly check if the incoming file has recent lines.

Re: script to save logs and send via email

Posted: Thu Sep 08, 2016 10:55 am
by gorebell
Hi

we have some hotspots running under RB951UI2HND (v 6.3) and we need to save all sites visited by our users and keep it 3 months (terrorism law)
could you please advise the exact script to run it

Thanks

Re: script to save logs and send via email

Posted: Thu Sep 15, 2016 4:39 am
by BrasDeutscher
To Analyse use Libre Office from Apache, free and very easy to use !

Re: script to save logs and send via email

Posted: Sun May 20, 2018 1:22 pm
by Boardy
This script stopped working with version 6.42.1 - changelog to 6.42.2 does not show any fix. I will give it a try, but anybody else having same issue?