Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8374

Python • Re: How do I get crontab to run a Python program

$
0
0
Thank you for your patience. First of all though, I certainly would not ask for an update to your guide.

I have spent time on this today and I am getting nowhere. I cannot find any cron related errors.
From Section 6.1 in your guide when entering:
@reboot ping /home/pi/Desktop/myprog.py 2>$HOME/ping.log
it returns:
bash: @reboot: command not found
in the ping.log file

It would. It's an example cron tab entry not an example command to run at the prompt.
Further questions/points if I may
1) Does the pi need to be rebooted after any change to the crontab file?

Only if you have an @reboot cronjob that you want to trigger. Timed jobs should run at the next specified time.
2) How do I know which crontab file to use (e.g. sudo crontab -e or just crontab -e or is there another one)

Generally you don't use sudo crontab -e unless you want to run the process as root (think admin if used to Windows) or unless the process needs to be run with those privileges.

It's the same guideline as for sudo: don't use it unless you absolutely have to.

There are other places. See sections 7.3, 7.4, and 7.5 Best advice is to pick one and stick to it for all cron jobs. My preference being crontab -e
3) Entering the grep line option from Section 6.1 results in no such file or directory being returned
4) I cannot find the /var/log/syslog file

I believe I explained that in my last post. At least for RPiOS Trixie. It may also apply to RPiOS Bookworm. I'm not sure exactly when that change came in.

You're obviously struggling with this so I'm going to do something I wouldn't normally* do and suggest a modified crontab entry for you to try:

Code:

* 22 * * * /usr/bin/python3 /home/pi/Desktop/myprog.py >$HOME/myprog.log 2>&1
That specifies the full path to your system python3 binary and sends all output (including any error messages) to myprog.log in the user's home directory. If you use root's crontab (sudo contab -e) that's /root.

*: Because you'll learn more by doing than you will by copy'n'paste.

Statistics: Posted by thagrol — Thu Oct 16, 2025 10:13 pm



Viewing all articles
Browse latest Browse all 8374

Trending Articles