Recently, I needed to run a python скрипт when raspberry started, checking messages in vk.com in an infinite loop.

The script does not work when writing it in either the crontab or /etc/rc.local .
Dancing with a tambourine and update-cd also did not bring results.
It starts only if you register it in .bashrc . (Everywhere he wrote absolute paths)

Python3 script.
The module works with vk.com: vk_api .

in crontab -e @reboot python3 /home/pi/bot/Start.py &> / dev / null

in /etc/rc.local python3 /home/pi/bot/Start.py &

 if __name__ == "__main__": try: main() except Exception as det: print(R + "\n Error: " + str(det) + G) 

(R and G - color in the terminal)

  • one
    show what you are writing to crontab, whether any errors are displayed. Write logs from the script? Maybe bring a piece of code in which you think there may be errors - apelsinka223
  • unix.stackexchange.com/questions/109804/… - the first thing to google @reboot, maybe it has a problem - apelsinka223
  • Add the code to the question, do not read it - apelsinka223
  • the path is better to specify the absolute, not relative: /каталог , not a каталог . - aleksandr barakin
  • made a mistake on the way, it was fixed - I. Fedotov

1 answer 1

I decided this is quite unusual.
The thing was that vk_api for some reason could not log my acc.
Therefore, at the beginning of the program, I had to ping the server from the network in order to verify that the Internet was working at that moment.

 def ping(host='google.com'): return os.system('ping -c 1 ' + host) == 0 while not ping() time.sleep(1) 
  • Usually such problems are solved by specifying dependencies on network (and other) services so that your task does not start before the network, home directory and other necessary resources become available raspberrypi-spy.co.uk/2015/10/… - jfs