Raspberry Pi crontab starts py script at bootup -> logging: error mysql 2002 (can't connect to local server)

元气小坏坏 提交于 2020-01-06 14:06:13

问题


A Raspberry Pi (raspian wheezy) has a cronjob, created as user pi with "sudo crontab -e" so it should has root grants.

ps aux | grep /home/.../myscript.py

...say it's owner is user "pi"!? (is this correct?)

The python script called from crontab is working fine if i call it from the terminal. It's reading data from UART (serial port), and save it into a mysql database. My python script got 'chmod 777' grants.

The crontab file:

@reboot sudo python /home/pi/pythonprogram/myscript.py & > /home/pi/pythonprogram/myscript.log

crontab log file:

Error mysql: 2002 Can't connect to local MYSQL server throught socket '/var/run/mysqld/mysqld.sock' (2)

May it be that my script is called first, before the server (mysql and apache) are running during the boot up process? Is there a way to prevent this?

What else could be the reason for those error?


回答1:


solved the problem in quite ugly way, but it's working now.

Just added:

time.sleep(5)

before trying to connect to mysql db.

I would be pleased if someone has a better solution.



来源:https://stackoverflow.com/questions/18805490/raspberry-pi-crontab-starts-py-script-at-bootup-logging-error-mysql-2002-ca

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!