0

I have a Raspberrypi 5 running bookworm and would like to run a python script at reboot. The script is in a virtual environment: /home/mipi/venv/Startup/Startup.py (where venv is the root directory for the virtual environment). So far I have been unsuccessful. The script runs flawlessly in Thonny.

Ownership and permissions on the script are:

-rwxrwx--- 1 mipi mipi 3382 Dec  8 16:44 Startup.py

Can someone please explain to me how to get the script to run on reboot?

When I put the following into crontab -e:

@reboot service /home/mipi/venv/bin/activate && /home/mipi/venv/Startup/Startup.py

The following is in the system log file:

Dec 09 08:31:20 mipi CRON[542]: pam_unix(cron:session): session opened for user mipi(uid=1000) by (uid=0)
  Dec 09 08:31:20 mipi CRON[637]: (mipi) CMD (source /home/mipi/venv/bin/python /home/mipi/venv/Startup/Startup.py)
  Dec 09 08:31:20 mipi CRON[542]: (CRON) info (No MTA installed, discarding output)
  Dec 09 08:31:20 mipi CRON[542]: pam_unix(cron:session): session closed for user mipi

When I enter the following in crontab -e:

@reboot /usr/bin/sleep 30 source /home/mipi/venv/bin/python /home/mipi/venv/Startup/Startup.py >/dev/null 2>&1

The following is in the log file:

Dec 09 09:02:31 mipi CRON[545]: pam_unix(cron:session): session opened for user mipi(uid=1000) by (uid=0)
Dec 09 09:02:31 mipi CRON[637]: (mipi) CMD (/usr/bin/sleep 30 source /home/mipi/venv/bin/python /home/mipi/venv/Startup/Start>
Dec 09 09:02:31 mipi CRON[545]: pam_unix(cron:session): session closed for user mipi

I tried entering the following in sudo crontab -e:

@reboot source /home/mipi/venv/bin/activate && /home/mipi/venv/Startup/Startup.py

And this is what was in the log file:

Dec 09 09:33:57 mipi CRON[604]: (root) CMD (source /home/mipi/venv/bin/activate && /home/mipi/venv/Startup/Startup.py)
Dec 09 09:33:57 mipi CRON[605]: (mipi) CMD (/usr/bin/sleep 30 source /home/mipi/venv/bin/python /home/mipi/venv/Startup/Startup.py >/dev>
Dec 09 09:33:57 mipi CRON[538]: (CRON) info (No MTA installed, discarding output)
Dec 09 09:33:57 mipi CRON[538]: pam_unix(cron:session): session closed for user root
Dec 09 09:33:57 mipi CRON[539]: pam_unix(cron:session): session closed for user mipi
1

1 Answer 1

0

Upon further digging, I found this works:

/home/mipi/venv/bin/python /home/mipi/Startup/Startup.py

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.