0
votes

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
instead of making a crontab at reboot i'll do a script in /etc/init.d + add a symlink in the /etc/rcX.d/ which will be fired after the mysql boot. - user1593705
thats what i tried and relinquished before... (seems much more complicated to me) - user972851

1 Answers

1
votes

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.