Hi, in the thread “tunnel troubleshot” in the General tab, i posted some issue with tunneling, and i want to get some script to have monitoring ipsec installed sa and append to existing file, but when I run script manualy via GUI, nothing happend, where is mistake?
:set time [/system clock get time]
:local file [/ip ipsec installed-sa print file=ipsec append]
:local contents [/file get $file contents]
:set contents ($contents . "\n" . $time)
/file set $file contents=$contents
}
When i run just
/ip ipsec installed-sa print file=ipsec append
it is OK, and file have been created. What is problem with the script?
Most likely you are trying to get more than 4096 bytes into a variable:
:local contents [/file get $file contents]
http://forum.mikrotik.com/t/file-size-limit-4096/113474/1
It is limit not to file - it is limit for variable size…
If you write text variable to file - you can write maximum 4096 bytes.
But, “:execute” have’t “append” option! And you can’t use it for add line to your’s log file.
And “/system clock print” have’t “append” option..
As an option, it is passible to use global variable - “/system script environment print” have “append” option!
And so we have:
:global TimeVar
:local SAfileName "ipsec.txt"
:set TimeVar [/system clock get time]
/ip ipsec installed-sa print file=$SAfileName append
/system script environment print file=$SAfileName append where name="TimeVar"
:set TimeVar
ipsec.txt:
# oct/20/2020 11:45:44 by RouterOS 6.47.4
# software id = 0Q17-AD9J
#
Flags: H - hw-aead, A - AH, E - ESP
# oct/20/2020 11:45:44 by RouterOS 6.47.4
# software id = 0Q17-AD9J
#
# NAME VALUE
0 TimeVar 11:45:44
# oct/20/2020 11:45:48 by RouterOS 6.47.4
# software id = 0Q17-AD9J
#
Flags: H - hw-aead, A - AH, E - ESP
# oct/20/2020 11:45:48 by RouterOS 6.47.4
# software id = 0Q17-AD9J
#
# NAME VALUE
0 TimeVar 11:45:48
On my router, every time I use “..print .. file .. append” the timestamp and RoOS information is added to the file. If you have the same thing, then you do not need to use a global variable for your task at all.