Page 1 of 1

last line only appears

Posted: Sun Feb 07, 2010 9:57 am
by akram
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

Re: last line only appears

Posted: Sun Feb 07, 2010 1:45 pm
by SurferTim
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.

Re: last line only appears

Posted: Sun Feb 07, 2010 3:25 pm
by akram
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?

Re: last line only appears

Posted: Sun Feb 07, 2010 3:33 pm
by Chupaka
: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"

Re: last line only appears

Posted: Sun Feb 07, 2010 3:35 pm
by akram
thanks alot
it works

Re: last line only appears

Posted: Sun Feb 07, 2010 3:42 pm
by akram
i works 100 % but i need to add enter better each line
is it possible?

Re: last line only appears

Posted: Sun Feb 07, 2010 3:47 pm
by Chupaka
you mean, in e-mail? try replacing '\n' with '\r\n'

Re: last line only appears

Posted: Sun Feb 07, 2010 3:50 pm
by SurferTim
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".

Re: last line only appears

Posted: Sun Feb 07, 2010 4:02 pm
by Chupaka
some windows programs don't recognize \n, so probably he needs "\r\n\r\n" :D

Re: last line only appears

Posted: Sun Feb 07, 2010 4:08 pm
by SurferTim
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".

Re: last line only appears

Posted: Sun Feb 07, 2010 4:41 pm
by akram
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

Re: last line only appears

Posted: Sun Feb 07, 2010 5:47 pm
by Chupaka
not multiply, but divide ))

replace
bytes=".[get $i bytes]."
with
bytes=".([get $i bytes] / 1024 / 1024)."M

Re: last line only appears

Posted: Sun Feb 07, 2010 7:25 pm
by akram
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"