I have a netwatch script writing log to a file, and I often hit the prehistoric 4096B limit for file/variable.
It seems there is no workaround for this, so I need to read the filesize and deal with it some other way (creating
new file if filesize>4000, removing some entries at the beginning etc).
But I didn’t find any way how to read it - do you know how to read it? Or use some workaround etc?
There is no limit on the file size.
The limit that you experience is because of the maximal size of a variable value, combined with the limitation
that you can only read or write files in a single action in scripts, not in a open/loop/close fashion where the loop
would do multiple read or write actions that each process part of the file.
You can setup logging to an external syslog server and do the processing there, if practical.
jotne: hmm, even though not all of our routers are able to reach internet, it is very interesting project and I’ll take a look at Splunk - I didn’t even know something like this existed.
pe1chl: I am not really fan of this word playing, I know how the variable limit works and that’s why I wrote “file/variable” limit in my post; no matter how we call it, in my situation I am able to write to file <4096B and I am not when the file reaches this limit.
I’d be very grateful for some loop example etc, I searched a lot and didn’t find and way to get past this limit, I tried to print the file and capture output to a file but it is the same problem. So I want to try to get the file value and if if exceeds let’s say 4000B, create a new file. Or any other possible workaround.
As I wrote jotne, I have some routers without internet connection or syslog server on local network, and I need to have log about ups and downs of certain ip.
So this i a 100% closed network for some system that are not near any form for internet connection?
It may be a solution to setup a server with two network card. One interface connected to the closed network and one to some internet.
Then it may use resylog to forward syslog messages. But this many not be acceptable due to security.
It of course depends on the actual thing you are trying to do.
Writing the file is not really a problem, you can e.g. use logging to a file and log single lines from a script.
However reading them back in a script is a problem, yes.
Having an open/loop/close method of processing files is on the requested features list.
But maybe there are other ways of solving your actual problem, e.g. keeping the data in an array as well as on disk.
Something like that, it is a state department with high level security policies, we need some routers/APs there for our stuff (not connected together though) and we agreed to have or allow no connections inside/outside and we are doing that.
Than script really is interesting and I’ll learn from it, but it overwrited the file every time (and get passed tge 4096B limit). But I need to append it to the file, I need all logs, not only the last one.
I’ll be happy for any solution how to write netwatch logs on one router (or my own netwatch script), and I’ll use any possible way I’ll be able to implement. I don’t insist on using the default netwatch, using scripts, nothing, any working way is great for me
/tool netwatch add down-script=“/log warning message="x.x.x.x is down"” host=x.x.x.x up-script=“/log info message="x.x.x.x is up"”
This writes the message to the log with tags “script, warning” or “script, info” and you can configure logging to write those to a file.
Then that file will grow beyond 4096 without problem (you set the max size).
this seems like a working workaround! I didn’t want to use logs in any way due to tons od dhcp etc records, but I missed the fact that I can redirect only script logs to a file of my choice, even with time already included and selectable number of rows.. this is probably a solution for my problem, I’ll test how it works in real but I am already able to write to a log file from my script, so I don’t see any problem there. thank you