bash脚本给出了不同的结果

时间:2016-05-05 15:58:03

标签: mysql linux bash

我有一个bash脚本启动一些python代码,在最新的raspbian下运行在RasPi上。如果我用sudo手动运行它运行正常,但是当它在启动时自动运行时我得到一个mysql错误。该脚本从/etc/rc.local

中的一行调用

脚本是

#!/bin/bash 
/home/control/solar/v10_1/control.py  >> '/home/control/solar/logs/control_X.X_start.log' 2>&1 &
echo "control started"  >> '/home/control/solar/logs/control_X.X_start.log'
echo "UID is $UID , EUID is $EUID" >> '/home/control/solar/logs/control_X.X_start.log'

启动后输出到日志

UID is 0 , EUID is 0
Traceback (most recent call last):
File "/home/control/solar/v10_1/control.py", line 42, in <module>
import variables    # global variables
File "/home/control/solar/v10_1/variables.py", line 13, in <module>
gv.db = MySQLdb.connect("localhost", "solar", "solar", db='solar') # database for logging
File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")

我已将所有路径设为绝对路径,两种情况下UID均为0,这会导致行为差异吗?

0 个答案:

没有答案