I'm writing a grammar for parsing PlantUML State diagrams and have the following doubt:
I had:
transition: STATE arrow STATE (":" event? guard? action?)? "\n"
arrow: ("->" | "-->" | "-left->" | "-right->" | "-up->" | "-down->")
But had to change to:
transition: STATE ("->" | "-->" | "-left->" | "-right->" | "-up->" | "-down->") STATE (":" event? GUARD? action?)? "\n"
Because, for my application, I don't need nor care which type of arrow is used; it is sufficient to know that an arrow was there to form the transition.
The question is: Is there a way to split the transition rule in other more manageable rules without the arrow type appearing in the parsed tree?
Full file at https://github.com/thomedes/PlantUML-Lark-EBNF. Feel free to comment / criticize. Trying to learn here 🤓
After RTFM, I've found that terminals whose name begins with underscore are not output to the tree, so I've changed it to:
transition: STATE _ARROW STATE (":" event? GUARD? ACTION?)? "\n"
_ARROW: "->" | "-->" | "-left->" | "-right->" | "-up->" | "-down->"
And now it works fine.
Not marking this as an accepted answer because I'm sure someone with more experience could give a better answer.
I have a file that is created by an application. The app is perpetually writing large volumes of data to the file.
I need to capture a copy of the last 10 lines of the file periodically and write it to another file without causing any file locking, which could impact the application writing the logFile.
How do I do that without impacting the application writing the logfile? i.e without causing any file locking.
logFile example
1452431219885,546,Item Details Request,200,OK,text,true,12562,91,91,271,ip-172-31-36-138,0,134
1452431219886,1300,Select Item Request,200,OK,text,true,28541,91,91,444,ip-172-31-36-138,0,209
1452431219889,210,Login Success Page Request,200,OK,text,true,29405,91,91,123,ip-172-31-36-137,0,27
1452431219898,217,Item Details Request,200,OK,text,true,10620,91,91,215,ip-172-31-36-135,0,106
1452431219900,1668,Logout and Exit Request,200,OK,text,true,19676,92,92,1133,ip-172-31-36-136,0,266
1452431219902,589,Search Page Request,200,OK,text,true,13392,91,91,296,ip-172-31-36-138,0,147
1452431219903,589,Save Basket Request,200,OK,text,true,17473,91,91,294,ip-172-31-36-138,0,147
1452431219908,1135,Search Results Request,200,OK,text,true,561615,91,91,229,ip-172-31-36-136,0,116
1452431219914,1114,Item Details Request,200,OK,text,true,93243,91,91,282,ip-172-31-36-138,0,138
1452431219921,825,Select Item Request,200,OK,text,true,24354,91,91,339,ip-172-31-36-135,0,161
Under most operating systems (i.e. BSDs, Linux, Mac, essentially anything not Windows), files never get locked unless the program explicitly requests it.
Even then, locks in these operating systems are only advisory, so won't affect programs which don't care about them.
So the answer is: almost anything that can get the last lines of the log, will do so without locking.
Obtain the last 10 lines
If I understand your question correctly, you can simply use:
# tail reads the input file and print out the last 10 lines (default)
tail /path/to/file.log > 10_lines.dump
# Change number of lines from default(10) to 5
tail -n 5 /path/to/file.log > 5_lines.dump
Show last lines every X seconds
If you need to do this periodically without saving the output you can use watch:
# watch show the output of the tail command every 5 seconds (default 2s)
watch -n 5 tail /path/to/file.log
# OR last 5 lines every 5 seconds
watch -n 5 tail -n 5 /path/to/file.log
Extract and save for future reference in background
Create a crontab file (name it file.crontab or as you wish) with an editor of your choice with this content:
# ** Crontab file schema **
# .------------------ [m]inute: [0 - 59] OR */x (every x minutes)
# | .-------------- [h]our: [0 - 23] OR */x (every x hours)
# | | .---------- [d]ay [o]f [m]onth: [1 - 31]
# | | | .------ [mon]th: [1 - 12] OR jan,feb,mar,apr...
# | | | | .-- [d]ay [o]f [w]eek: [0 - 6] (Sunday can be 0 or 7)
# | | | | | (also: sun,mon,tue,wed,thu,fri,sat)
# m h d mon dow
# * * * * * command executed every minute with my user permission
# --
# Execute tail every 5 minutes and append last 10 lines of input to log.extract
*/5 * * * * tail "/path/to/file.log" >> "/path/to/log.extract"
Install it on your system using crontab:
crontab file.crontab