I would like to display the content of a text file which its content is completely refreshed every second on the command screen.
Here the Python code to give you guys an idea:
def show_status():
while True:
#Delete the content
with open("/home/pi/log/heartbeat.txt", 'w'):
pass
#Print new content
db_file = open("/home/pi/log/heartbeat.txt", 'a')
db_file.write('###################################################################################################\n')
db_file.write('STATUS SENSOR ALIVE PIN HEARTBEAT LAST PIN HIGH\n')
db_file.write('###################################################################################################\n')
db_file.close()
for i in range(0,4):
report_sensor(i)
sleep(1)
By using tail I get a "file truncated" error and the content keep flooding my screen repeatedly.
Is there a command which I could use for it?
Thanks
As suggested by Karlp, the command below did the trick:
watch -n 1 cat /home/pi/log/heartbeat.txt