0

I created a python script that I would like to execute at each startup. I modified the etc/rc.local, but I don't get the script to run.

etc/rc.local addition (I added the sleep thinking it may help):

(sleep 10; /usr/bin/python3 /home/pi/mower-gps-tracking/app/gps_logger.py)&

imports in the different python scripts (I don't know if it matters):

from ftplib import FTP
import os
import serial
import time
import threading
from gpiozero import LED, Button

When I start the etc/rc.local manually via a ssh command, it runs fine.

Any idea what I'm missing ?

4
  • Recent versions of Linux no longer run the /etc/rc.local script. You may need to use systemd or crontab. Have a look at this question. Commented Aug 17, 2018 at 22:49
  • Stack Overflow is for programming questions, not questions about using or configuring Linux and its applications. Super User or Unix & Linux would be better places for questions like this.
    – Barmar
    Commented Aug 17, 2018 at 23:59
  • Systemd is working fine, thank you for the tip John Anderson
    – Laurent R
    Commented Aug 18, 2018 at 1:16
  • Most often when same command is not running in /etc/rc.local it's a simple problem of changes in Environment, mainly PATH or in this case python specific environment variables, if any. Commented Jun 12, 2023 at 4:41

2 Answers 2

0

Check if the script (rc.local) is executable ie. has the 'x' attribute set.

And you will probably need a

#!/bin/bash

as line #1 of your script.

Hope this helps. And as per Barmar above, probably more approp in the Unix forums.

0

I tried this on my linux box no issues .. As a test create a script that will wrap your script, have it write to a tmp file so you can see if it actually runs. Use nohup and & in your scripts.

/etc/rc.local:

nohup /root/script.sh &

/root/script.sh:

#!/bin/bash
echo "I'm starting something .." > /tmp/startup_thing.log
/root/gps_logger.py

note: all scripts need to be chmod a+x file.ext. if it's not running check for the file /tmp/startup_thing.log . If it's there then you have some other issue. If it isn't then rc.local isn't working.

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.