Community discussions

 
xakou
newbie
Topic Author
Posts: 30
Joined: Fri Jun 15, 2007 11:25 am

script to save logs and send via email

Sat Mar 01, 2008 10:12 am

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 ?
 
User avatar
Letni
Member
Member
Posts: 375
Joined: Tue Dec 05, 2006 5:16 am
Location: South Carolina

Re: script to save logs and send via email

Sun Mar 02, 2008 7:16 am

/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
 
xakou
newbie
Topic Author
Posts: 30
Joined: Fri Jun 15, 2007 11:25 am

Re: script to save logs and send via email

Sun Mar 02, 2008 1:40 pm

/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 ?
 
User avatar
jordantrx
Long time Member
Long time Member
Posts: 505
Joined: Tue Oct 23, 2007 8:58 pm
Location: WAY upstate NY

Re: script to save logs and send via email

Sun Mar 02, 2008 4:05 pm

/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:
~Agricultural WISP "ZONE"~ Beware of oncoming cattle and dont hit the farmer!!! I need to ask him about using his silo for an AP first"~

*Automated Billing Installer* http://wiki.mikrotik.com/wiki/AutomatedBilling Built by Krige ;-)
 
itsh.net
Member Candidate
Member Candidate
Posts: 115
Joined: Mon Jan 23, 2006 12:00 pm
Location: Germany
Contact:

Re: script to save logs and send via email

Thu May 15, 2008 8:41 pm

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"

 
User avatar
Letni
Member
Member
Posts: 375
Joined: Tue Dec 05, 2006 5:16 am
Location: South Carolina

Re: script to save logs and send via email

Fri May 16, 2008 6:01 am

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
 
itsh.net
Member Candidate
Member Candidate
Posts: 115
Joined: Mon Jan 23, 2006 12:00 pm
Location: Germany
Contact:

Re: script to save logs and send via email

Fri May 16, 2008 11:01 am

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

 
er
just joined
Posts: 13
Joined: Sat Jun 03, 2006 12:38 am

Re: script to save logs and send via email

Mon May 19, 2008 12:50 pm

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
 
itsh.net
Member Candidate
Member Candidate
Posts: 115
Joined: Mon Jan 23, 2006 12:00 pm
Location: Germany
Contact:

Re: script to save logs and send via email

Mon May 19, 2008 1:36 pm

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..
 
FlorinHiT
just joined
Posts: 4
Joined: Sun Nov 07, 2010 9:09 am

Re: script to save logs and send via email

Fri Mar 30, 2012 5:21 pm

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)
 
Ehman
Member
Member
Posts: 363
Joined: Mon Nov 15, 2010 10:49 pm

Re: script to save logs and send via email

Wed Oct 23, 2013 9:03 pm

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
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6267
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: script to save logs and send via email

Thu Oct 24, 2013 1:09 pm

please upgrade to newer RouterOS version as scripting has had a lot of changes since 6.3
 
Ehman
Member
Member
Posts: 363
Joined: Mon Nov 15, 2010 10:49 pm

Re: script to save logs and send via email

Thu Oct 24, 2013 1:15 pm

I don't trust the new versions of ros [past experience] ...always tends to be full of bugs
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 23592
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: script to save logs and send via email

Thu Oct 24, 2013 1:15 pm

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"?
No answer to your question? How to write posts
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2389
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: script to save logs and send via email

Thu Oct 24, 2013 1:22 pm

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".
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
Ehman
Member
Member
Posts: 363
Joined: Mon Nov 15, 2010 10:49 pm

Re: script to save logs and send via email

Thu Oct 24, 2013 1:58 pm

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
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6267
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: script to save logs and send via email

Thu Oct 24, 2013 3:12 pm

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).
 
Ximi87
just joined
Posts: 22
Joined: Sun Aug 25, 2013 1:29 pm
Location: Tirana Albania
Contact:

Re: script to save logs and send via email

Wed Jul 30, 2014 8:44 pm

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.
You do not have the required permissions to view the files attached to this post.
 
jarda
Forum Guru
Forum Guru
Posts: 7560
Joined: Mon Oct 22, 2012 4:46 pm

Re: script to save logs and send via email

Tue Aug 05, 2014 9:39 pm

Why so complicated? Just log into file and sent the file regularly as email attachment.
 
Ximi87
just joined
Posts: 22
Joined: Sun Aug 25, 2013 1:29 pm
Location: Tirana Albania
Contact:

Re: script to save logs and send via email

Fri Aug 15, 2014 7:29 pm

can you tell me how to do that...

with script or with winbox.
 
jarda
Forum Guru
Forum Guru
Posts: 7560
Joined: Mon Oct 22, 2012 4:46 pm

Re: script to save logs and send via email

Sat Aug 16, 2014 7:42 am

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...
 
pgh321
newbie
Posts: 48
Joined: Fri Jan 03, 2014 7:35 pm

Re: script to save logs and send via email

Fri Jan 09, 2015 10:28 pm

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...
 
jarda
Forum Guru
Forum Guru
Posts: 7560
Joined: Mon Oct 22, 2012 4:46 pm

Re: script to save logs and send via email

Sun Jan 11, 2015 4:50 am

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.
 
pgh321
newbie
Posts: 48
Joined: Fri Jan 03, 2014 7:35 pm

Re: script to save logs and send via email

Sun Jan 11, 2015 1:19 pm

Yes, but if you are using your script above, how do you deal with it? How often do you send your file? thank you
 
jarda
Forum Guru
Forum Guru
Posts: 7560
Joined: Mon Oct 22, 2012 4:46 pm

Re: script to save logs and send via email

Sun Jan 11, 2015 2:15 pm

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.
 
gorebell
just joined
Posts: 10
Joined: Thu Sep 01, 2016 1:05 pm

Re: script to save logs and send via email

Thu Sep 08, 2016 10:55 am

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
 
User avatar
BrasDeutscher
newbie
Posts: 43
Joined: Sat Sep 03, 2016 12:31 am
Location: Brazil

Re: script to save logs and send via email

Thu Sep 15, 2016 4:39 am

To Analyse use Libre Office from Apache, free and very easy to use !
 
Boardy
just joined
Posts: 4
Joined: Sun Apr 01, 2018 11:01 am

Re: script to save logs and send via email

Sun May 20, 2018 1:22 pm

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?

Who is online

Users browsing this forum: roonders and 4 guests