问题
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