0

I want to execute a script at startup using rc.local. For this I use the following file:

#!/bin/sh -e


/usr/bin/python /public/test.py&
exit 0

This testfile should write something into another file, just for test purposes. And not even that works. But if I write something like

echo "some test output" >> /public/rc.log

everything works fine and I get an additional line.

Later on I want to start a programm measuring all kinds of things. For this it must access GPIO, I2C and W1. I'm sure at the point where rc.local gets started a lot of libaries aren't ready yet to be used. Is there any trigger that tells me that now everything is ready? Something like the documentReady event in Javascript, but on raspbian?

UPDATE: I also tried crontab, where I did the following

First I typed crontab -e then wrote @reboot /usr/bin/python /public/cron.py. In this file I wrote

   with open("rc.log", "a") as f:
   f.write("Hello, cronjob\n")
   f.close()

But also: Nothing happens.

3
  • Did you use that exact indentation for your Python script, or did it just copy incorrectly? The code used here would cause an IndentationError. It might be worth setting up logging for rc.local and including the output to see if anything gets logged.
    – Aurora0001
    Jan 27 '18 at 9:41
  • 1
    rc.local is a SysV service. systemd init services run asynchronously. The only way to ensure required services are started is to use a systemd service with nominated dependencies.
    – Milliways
    Jan 27 '18 at 9:49
  • yes I have logging file. I log things with the following command: /usr/bin/python /public/main.py >> /public/conOut.log written in rc.local. Surprisingly somethines I get a log result and somethimes I don't. and @Milliways how exactly can I use a 'systemd service with nominated dependencies' this sounds like it would solve all my problems ^^ Jan 27 '18 at 10:48

Your Answer

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

Browse other questions tagged or ask your own question.