1

I have a script called BOAT.py and it lives in /home/pi/.

I want to autostart it at boot and I did a lot of research about doing so. I found many ways but none of them work.

I tried writing sudo python BOAT.py in the /etc/rc.local, I created a launcher.sh script and added it in crontab -e, I created a desktop file and added it to the autostart folder in the .config file, and I tried writing to .bashrc (that one says unexpected end but) nothing works.

The script just has to start at login or boot.

Thanks for any help

Edit:

The script runs if invoked from the terminal. In the /etc/rc.local I have this:

sudo python BOAT.py&

and in the crontab U have a script called launcher.sh. The launcher.sh file has this code:

cd /
cd /home/pi/BOAT.py   
cd/
  • can we see your code, crontab entry, directory permissions? does the script run if you invoke it from the command line? – Steve Robillard Aug 6 '14 at 11:33
  • Yes. The script runs if invoked from the terminal. In the /etc/rc.local I have this: sudo python BOAT.py& – Juliane Kakoli Aug 6 '14 at 11:40
  • in the crontab i have a script called launcher.sh The launcher.sh file has this code: cd / ##next line cd home/pi/BOAT.py ##next line cd/ – Juliane Kakoli Aug 6 '14 at 11:40
  • what is the actual line in the crontab entry? What are the permissions on the file aka the output of ls -la in the directory where the python file is located. shouldn't the second line of your launcher.sh code look like "sudo pyhton /home/BOAT.py?" – Steve Robillard Aug 6 '14 at 12:00
  • the permissions are set to read and write and the file is executable – Juliane Kakoli Aug 6 '14 at 12:01
4

Commands in the rc.local file are normally run as the root user anyway, so you don't really need the 'sudo' part of the command.

You may need to explicitly specify where your python interpreter is though, and you will certainly need the full path to your script.

Run

which python

and use the result from that command to update your rc.local file. The example below assumes that the 'which python' command returned '/usr/bin/python'. The rc.local file will end up something like this

/usr/bin/python /home/pi/BOAT.py

If you need to redirect the output from your script, you can use a line like this

/usr/bin/python /home/pi/BOAT.py >/tmp/BOAT.out 2>/tmp/BOAT.err

Anything your script sends to sdtout will now be put in /tmp/BOAT.out, and any error messages generated by your script will be in /tmp/BOAT.err.

If you want to use cron instead, your launcher.sh script just needs to be a single line exactly as above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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