1

Does anyone know about crontabs here?

I've programmed a fine dust station with values ​​acquisition, LCD display and so on. The particulate matter station is to be exhibited at the university, but the prerequisite for this is that the respective Python script runs itself at least once a minute (if it has been aborted), if a reboot is executed by mistake or the WLAN connection is aborted. Unfortunately, I have not come any further since last night. The whole project is already finished, it just fails at the crontab.

https://abload.de/img/unbenannt6cksv.jpg

It looks like that, but I have already tried a thousand other things and he just does nothing at all. Is there an alternative to the cronjob for such a thing or do I overlook a triviality? Would be annoying if it fails now but I am at the end of my knowledge. Chmod, etc. I've already tried a lot of things.

Thanks for the help!

3
  • 1
    It is doubtful that this is specific to the Pi, but without details who knows?
    – Milliways
    Jun 23, 2019 at 10:28
  • I am using a raspberry zero for this project and i am connecter via WinSCP and SSH connection for the command console. The python Script is located @ home/pi/lufi/luftdaten-python and is named custom_main.py Jun 23, 2019 at 10:35
  • You should post text, not images of text. And if you paste the command into the shell, you should see what is wrong.
    – RalfFriedl
    Jun 23, 2019 at 12:47

1 Answer 1

1

This is your crontab line in your image:

* * * * * cd / & cd home/pi/lufi/luftdaten-python & python3 custom_main.py &

You need to use a double ampersand (&&) in your crontab, not a single one like you've got (&).

The single ampersand sends a command into the background. Definitely not what you want here. The double ampersand means "run this next command after finishing the one before it".

I'd rewrite the whole thing like this:

* * * * * /usr/bin/python3 /home/pi/lufi/luftdaten-python/custom_main.py > /tmp/cron_custom_main.log 2>&1 &

That'll log any errors etc to the /tmp/cron_custom_main.log file if any occur. The ampersand at the end will force the script into the background, I'm assuming that's what you wanted.

Run the full command at the command line before updating the crontab to ensure it works. The python3 binary might not be in /usr/bin on your system.

1
  • Just to be pedantic, && is actually the "AND" operator so the next command is run only if the previous one completed and exited with a "true" exit code. Compare the output of true && echo "Hello" and false && echo "Goodbye". Jul 24, 2019 at 19:26

Your Answer

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

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