0

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.

2
  • Maybe the watchdog output is redirected to stderr. Try something like: python_pogram &>>/home/admin/Desktop/main/log.log or python_pogram >> /home/admin/Desktop/main/log.log 2>&1 Commented Dec 22, 2023 at 0:00
  • 2
    Not sure what you're running (you don't mention it), but consider using a systemd service instead of a crontab and collect logs using journalctl instead of logging to a file on disk.
    – Panki
    Commented Dec 22, 2023 at 1:17

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.