Anybody using Scheduled Tasks to run a python program on boot up? How did you do it? I having problems running a script from Scheduled Tasks but can start it in Terminal.
By "Scheduled Tasks", I will assume you are speaking of
cron. If my assumption is correct, you should first read this documentation, and then you should read
man cron and
man crontab. This will get you up to speed on the basics.
As for your question, you will use the
@reboot facility in your
crontab. If you're having trouble running it, but it runs OK from the command line, there are two possibilities:
When you run a program from the command line, it runs in the environment (env) of the user (pi?) that invoked the program. That environment includes permissions, and a PATH (i.e.
echo $PATH). When you run a program from cron, the program will NOT, in general, run in the same environment, and therefore the PATH will be different. The way to work around this is to use full path specs for all files and programs needed in your script.
Scripts run under
cronmay fail unexpectedly when using the
cronmaintains no awareness of whether or not the resources required to execute a command are available before attempting the execution. Redirecting
stderrto a log file in your
croncommand may give you some insights on this - here's an example that writes
stderrto a file named
cronjoblogin user pi's home directory:
@reboot /usr/bin/python3 ~/PiPyMailer/testmail2.py > /home/pi/cronjoblog 2>&1
If the issue is that the resources needed aren't available when
@reboot, add a
sleep 30; command before your script. This will allow the system reboot to progress and likely complete before starting your script. You should experiment with the "sleep time" as 30 seconds may be overkill.