I'm working on script which will run Bandwidth Test, save result to variable, send email with result, save result to disk and send it to FTP (where I create graph from values).
Script is working fine, till I reach the ANNOYING variable limit of 4096 and can't write to file anymore.
Here is the whole script:
Code: Select all
:local rxc
:local rxcA
:local rxcB
:local rxcC
:local rxta
:local rxtaA
:local rxtaB
:local rxtaC
:local sysname [/system identity get name]
:local datetime "$[/system clock get date] $[/system clock get time]"
:log info "Bandwidth-test start"
/tool bandwidth-test xxxx protocol=tcp direction=receive duration=10s do={
:set $rxcA ($"rx-current" / 1000)
:set $rxcB ($rxcA / 1000 * 1000)
:set $rxcC ($rxcA - $rxcB)
:set $rxcB ($rxcB / 1000)
:set $rxc "$rxcB.$rxcC"
:set $rxtaA ($"rx-total-average" / 1000)
:set $rxtaB ($rxtaA / 1000 * 1000)
:set $rxtaC ($rxtaA - $rxtaB)
:set $rxtaB ($rxtaB / 1000)
:set $rxta "$rxtaB.$rxtaC"
}
:log info "Bandwidth-test done"
:log info "Sending info by email"
/tool e-mail send to="xxxx" cc="xxxx,xxxx" subject="Bandwidth-test done : $sysname" body="$sysname \n $datetime \n \n Result : \n RX speed $rxc Mbps/s \n \n RX total average $rxta Mbps/s"
:delay 5s;
:log info "Saving file"
/file
:if ([:len [find where name="test.txt"] ] = 0) do={ print file=test.txt; :delay 2s; set "test.txt" content="" }
set "test.txt" contents="$[get "test.txt" contents]$datetime,$rxc\r\n"
:log info "File saved"
:delay 5s;
:log info "Uploading to FTP"
/tool fetch address=xxxx src-path="test.txt" user=xxxx mode=ftp password=xxxx dst-path="test.txt" upload=yes
:log info "Upload done"
}
Code: Select all
/system script environment print append where name="TimeVar" or name="rxc"
# NAME VALUE
0 TimeVar jan/28/2023 22:21:35
2 rxc 962.88
and saving them to file:
Code: Select all
:set TimeVar ([ / system clock get date ] . " " . [ / system clock get time ])
/system script environment print file=$fileName append where name="TimeVar" or name="rxc"
# jan/28/2023 23: 3:14 by RouterOS 7.7
# software id = DWYN-2ET8
#
Columns: NAME, VALUE
# NAME VALUE
0 TimeVar jan/28/2023 23:03:14
1 rxc 958.930
# jan/28/2023 23: 3:18 by RouterOS 7.7
# software id = DWYN-2ET8
#
Columns: NAME, VALUE
# NAME VALUE
0 TimeVar jan/28/2023 23:03:18
1 rxc 958.227
But here I'm lost, because due to my poor skills I don't know how to parse it to output like in my .csv file:
jan/28/2023 23:03:14,958.930
jan/28/2023 23:03:18,958.227
Thanks for pointing to any direction.
P.S. I started scripting in RouterOS yesterday, so be kind please.