Community discussions

MikroTik App
 
akram
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 88
Joined: Wed Aug 10, 2005 4:58 pm

last line only appears

Sun Feb 07, 2010 9:57 am

here is the script
:local text

:set text [/ip firewall filter {:foreach i in=[find] do={:put ("src-address=".[get $i src-address]." dst-address=".[get $i dst-address]." bytes=".[get $i bytes]);}} ]

:log info "testing - $text"

/tool e-mail send server="192.168.1.134" from="noreply@domain.com" to="me@domain.com" subject="report" body="report -
$text

Regards,
Akram


it only give me the last line in the log and also in the email , is there a way to fix my script to make it all the data list? thanks everyone
Last edited by akram on Mon Feb 08, 2010 1:47 am, edited 1 time in total.
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: last line only appears

Sun Feb 07, 2010 1:45 pm

When you set the "text" variable, you are overwriting the previous values. Try this:
:set text ("This is line 1\n")
:set text ($text . "This is line 2\n")
The "\n" inserts a line feed (newline). Note on the second "set", it inserts the previous "$text" entry before the second line is added.
 
akram
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 88
Joined: Wed Aug 10, 2005 4:58 pm

Re: last line only appears

Sun Feb 07, 2010 3:25 pm

sorry i don't understand where i can put the line u mean

but i tried but still give me all the lines same the last line

can u edit my script and tell me?
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8712
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: last line only appears

Sun Feb 07, 2010 3:33 pm

:local text ""

/ip firewall filter
{
  :foreach i in=[find] do={
    :set text ($text."src-address=".[get $i src-address]." dst-address=".[get $i dst-address]." bytes=".[get $i bytes]."\n");
  }
}

:log info "testing - $text"
 
akram
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 88
Joined: Wed Aug 10, 2005 4:58 pm

Re: last line only appears

Sun Feb 07, 2010 3:35 pm

thanks alot
it works
 
akram
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 88
Joined: Wed Aug 10, 2005 4:58 pm

Re: last line only appears

Sun Feb 07, 2010 3:42 pm

i works 100 % but i need to add enter better each line
is it possible?
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8712
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: last line only appears

Sun Feb 07, 2010 3:47 pm

you mean, in e-mail? try replacing '\n' with '\r\n'
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: last line only appears

Sun Feb 07, 2010 3:50 pm

Hey Chupaka! Thanks for the code. Very early SuperBowl Sunday here and I am just gettting some coffee in me now. I think he means a blank line between the lines. I use "\n\n".
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8712
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: last line only appears

Sun Feb 07, 2010 4:02 pm

some windows programs don't recognize \n, so probably he needs "\r\n\r\n" :D
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: last line only appears

Sun Feb 07, 2010 4:08 pm

some windows programs don't recognize \n, so probably he needs "\r\n\r\n" :D
You may be correct. I have checked it with Outlook, Outlook Express, and Thunderbird (Linux) only. It is possible that port 80 email readers would not like the single "\n".
 
akram
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 88
Joined: Wed Aug 10, 2005 4:58 pm

Re: last line only appears

Sun Feb 07, 2010 4:41 pm

i tested and it works thanks with \r\n\r\n
i wanna do something else

i want the bytes appear in MB

like src=192.168.1.3 bytes = 195 MB

how can i do that ,how to muliteply the byte to 1024 and add MB in the line

plz help
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8712
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: last line only appears

Sun Feb 07, 2010 5:47 pm

not multiply, but divide ))

replace
bytes=".[get $i bytes]."
with
bytes=".([get $i bytes] / 1024 / 1024)."M
 
akram
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 88
Joined: Wed Aug 10, 2005 4:58 pm

Re: last line only appears

Sun Feb 07, 2010 7:25 pm

perfect ,thanks very very much

here the hole script for everyone who want it
:local text ""
:local MB

:set MB " MB"


/ip firewall filter
{
  :foreach i in=[find] do={
    :set text ($text."src-address=".[get $i src-address]." dst-address=".[get $i dst-address]. " bytes=".([get $i bytes] / 1024 / 1024).$MB."\r\n\r\n" )
;
  }
}

:log info "test Download/Upload Report - $text

------- Report Ends -------"


/tool e-mail send server="192.168.1.134" from="noreply@domain.com" to="someone@domain.com" subject="Manual usage report" body="Download & Upload report - 
$text


Regards,
someone@domain.com"