I need to only allow the file to contain 5000 lines of data before deleting the oldest data as the python script outputs new data (Similar to the 'tail command in bash'). I would like to be able to observe the data as it's being generated by viewing the text file that the script is outputting to. I need it to be able to run in the background without the need for the terminal, or in this case ssh session, to be active. At the beginning of the python script that outputs all the data, I tried something along the lines of:
import sys
sys.stdout = open(tail -c 1G > 'output.txt', 'w', buffering=1)
But to no avail. I am not opposed to having a bash script handle the python file, but I would prefer to simply run the python script and have it's output directed to a separate file as mentioned above if possible.