I used to have only one Python script, the output of which would be directed to a log file.
It works like this: I have it in autostart
, using crontab
@reboot /bin/sleep 30; sudo /usr/bin/python3 -u /home/admin/Desktop/main/main.py >> /home/admin/Desktop/main/log.log
This just waits 30 seconds after reboot to start the python script and direct the output to the log file.
Now I made a second python script, which basically watches over the activity of that script, but also writing any relevant data to that same log file. I added it just the same way I did the one before:
@reboot /bin/sleep 40; sudo /usr/bin/python3 -u /home/admin/Desktop/main/mainWatchdog.py >> /home/admin/Desktop/main/log.log
However, my problem right now is, that any output of the watchdog
is not written to the log file.
I am not too familiar with this topic, so I am not sure if it's even possible to write to the same file using this method.
watchdog
output is redirected to stderr. Try something like:python_pogram &>>/home/admin/Desktop/main/log.log
orpython_pogram >> /home/admin/Desktop/main/log.log 2>&1
systemd
service instead of a crontab and collect logs usingjournalctl
instead of logging to a file on disk.